From 6f9c49572062d6509c54cb3cf46d693a589089b4 Mon Sep 17 00:00:00 2001 From: Robb Lovell Date: Thu, 17 Jan 2013 11:16:52 -0800 Subject: [PATCH 1/2] added 'all' method to hasMany in abstract-class.js to correctly support a 'many' collection. added .idea to .gitignore to ignore WebStorm projects. --- .gitignore | 1 + lib/abstract-class.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/.gitignore b/.gitignore index 64a8281a..f3d45af1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ doc coverage.html coverage v8.log +.idea** .DS_Store diff --git a/lib/abstract-class.js b/lib/abstract-class.js index 453794b7..6cb2eb0e 100644 --- a/lib/abstract-class.js +++ b/lib/abstract-class.js @@ -839,6 +839,7 @@ AbstractClass.hasMany = function hasMany(anotherClass, params) { return {where: x}; }, { find: find, + all: all, destroy: destroy }); @@ -857,6 +858,23 @@ AbstractClass.hasMany = function hasMany(anotherClass, params) { }.bind(this)); } + function all(filter,cb) { + if (!filter) { + filter = {}; + } + if (!filter.where) { + filter.where = {}; + } + filter.where[fk] = this.id.toString(); + + anotherClass.all(filter,function(err,inst){ + if (err) return cb(err); + if (!inst) return cb(null,[]); + else return cb(null,inst); + + }.bind(this)); + } + function destroy(id, cb) { this.find(id, function (err, inst) { if (err) return cb(err); From 84a9582bc0d2105aef0be0a0f2dd7db6f0a26429 Mon Sep 17 00:00:00 2001 From: Robb Lovell Date: Thu, 17 Jan 2013 12:00:59 -0800 Subject: [PATCH 2/2] attempted to write a test for hasmany all function. this commit has it commented out --- test/common_test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/common_test.js b/test/common_test.js index 3caa8890..329a437e 100644 --- a/test/common_test.js +++ b/test/common_test.js @@ -542,6 +542,29 @@ function testOrm(schema) { it('hasMany should be cached', function (test) { //User.create(function (e, u) { // u.posts.create({}, function (e, p) { + // find all posts for a user. + /* User.all(function (err,users) { + for (var i=0;i