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

Support nested collections again #17

Open
ahamid opened this issue Sep 25, 2011 · 2 comments
Open

Support nested collections again #17

ahamid opened this issue Sep 25, 2011 · 2 comments

Comments

@ahamid
Copy link
Contributor

ahamid commented Sep 25, 2011

A change was made in the recent rewrite which appears to have broken nested collections. The problem is in 'extract_collection_name' - only the first name component will ever be returned. E.g.

/patients/<id> -> patients
/patients/<id>/procedures -> patients

Below is a JS patch which more conservatively strips trailing id but otherwise preserves the rest of the url:

--- backbone-couchdb.js 2011-09-25 17:07:25.287049243 -0400
+++ backbone-couchdb.js 2011-09-25 17:06:17.059060804 -0400
@@ -38,8 +38,18 @@
           _name = _name.slice(1, _name.length);
         }
         _splitted = _name.split("/");
-        _name = _splitted.length > 0 ? _splitted[0] : _name;
+        
+        if (_splitted.length > 0) {
+          if (model.id == _splitted[_splitted.length -1]) {
+            _splitted.pop();
+          }
+          _name = _splitted.join('/');
+        }
+
+        if (_name.indexOf("/") === 0) {
         _name = _name.replace("/", "");
+        }
+
         return _name;
       },
       make_db: function() {
@janmonschke
Copy link
Owner

Does the CouchDB API provide success for nested collections?

@ahamid
Copy link
Contributor Author

ahamid commented Oct 8, 2011

as far as i understand a collection is just a view on a certain field, for example, the 'collection' field. this can be any string, and the patch above allows this string to be the id of a different model. i don't think there is any special about nesting to support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants