Allow collections to specify their own design document #38

Merged
merged 2 commits into from Apr 2, 2012

Projects

None yet

2 participants

@radicand

Much like we can specify a view other than "byCollection", this PRQ allows a collection to specify its own design document if it differs from the default.

@janmonschke
Owner

I just accepted another PRQ in the main repo, can you fetch the changes and merge them, so I can merge this one to the main repo as well?

@radicand

Done-- It should merge now, let me know if you need anything else.

@janmonschke
Owner

Awesome thx :)
If you like you can write a little text about that feature so I can put in in the documentation under 'recipes' at http://janmonschke.com/projects/backbone-couchdb.html

@janmonschke janmonschke merged commit bd0a2ea into janmonschke:master Apr 2, 2012
@radicand

Heh, it's pretty straightforward:

If you need your collection to be sourced from a different design document, you can use the db.ddoc Collection option to specify a new design document:

  Backbone.couch_connector.config.ddoc_name = "my_main_design_doc"

  var mainCollection = Backbone.Collection.extend({
    db : {
      view : "myCollection"
    }
    ....
  });

  var otherCollection = Backbone.Collection.extend({
    db : {
      view : "myCollection",
      ddoc : "my_other_design_doc"
    }
    ....
  });

This results in mainCollection sourcing from _design/my_main_design_doc/_view/myCollection and otherCollection sourcing from _design/my_other_design_doc/_view/myCollection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment