Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow collections to specify their own design document #38

Merged
merged 2 commits into from
Apr 2, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions backbone-couchdb.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ Backbone.couch_connector = con =
# Reads all docs of a collection based on the byCollection view or a custom view specified by the collection
read_collection : (coll, opts) ->
_view = @config.view_name
_ddoc = @config.ddoc_name
_list = @config.list_name
keys = [@helpers.extract_collection_name coll]
if coll.db?
coll.listen_to_changes() if coll.db.changes or @config.global_changes
if coll.db.view?
_view = coll.db.view
if coll.db.ddoc?
_ddoc = coll.db.ddoc
if coll.db.keys?
keys = coll.db.keys
if coll.db.list?
Expand Down Expand Up @@ -103,9 +106,9 @@ Backbone.couch_connector = con =
delete _opts.keys

if _list
@helpers.make_db().list "#{@config.ddoc_name}/#{_list}", "#{_view}", _opts
@helpers.make_db().list "#{_ddoc}/#{_list}", "#{_view}", _opts
else
@helpers.make_db().view "#{@config.ddoc_name}/#{_view}", _opts
@helpers.make_db().view "#{_ddoc}/#{_view}", _opts


# Reads a model from the couchdb by it's ID
Expand Down
8 changes: 5 additions & 3 deletions backbone-couchdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,18 @@ backbone-couchdb.js is licensed under the MIT license.
}
},
read_collection: function(coll, opts) {
var keys, _opts, _view, _list,
var keys, _opts, _view, _ddoc, _list
_this = this;
_view = this.config.view_name;
_ddoc = this.config.ddoc_name;
_list = this.config.list_name;
keys = [this.helpers.extract_collection_name(coll)];
if (coll.db != null) {
if (coll.db.changes || this.config.global_changes) {
coll.listen_to_changes();
}
if (coll.db.view != null) _view = coll.db.view;
if (coll.db.ddoc != null) _ddoc = coll.db.ddoc;
if (coll.db.keys != null) keys = coll.db.keys;
if (coll.db.list != null) _list = coll.db.list;
}
Expand Down Expand Up @@ -96,9 +98,9 @@ backbone-couchdb.js is licensed under the MIT license.
delete _opts.keys;
}
if (_list != null) {
return this.helpers.make_db().list("" + this.config.ddoc_name + "/" + _list, "" + _view, _opts);
return this.helpers.make_db().list("" + _ddoc + "/" + _list, "" + _view, _opts);
} else {
return this.helpers.make_db().view("" + this.config.ddoc_name + "/" + _view, _opts);
return this.helpers.make_db().view("" + _ddoc + "/" + _view, _opts);
}
},
read_model: function(model, opts) {
Expand Down