Skip to content
Browse files

[api] return err if child is not found with getChild.

  • Loading branch information...
1 parent e24171f commit e483234183f90e26c8014ed65f5314c49ec7cd9c @nrw nrw committed
Showing with 19 additions and 15 deletions.
  1. +9 −15 lib/resourceful/resource.js
  2. +10 −0 test/relationship-test.js
View
24 lib/resourceful/resource.js
@@ -558,21 +558,15 @@ function relationship(factory, type, r, options) {
var rstringi = rstring + '_ids';
p[rstringi] = p[rstringi] || [];
-
- if (p[rstringi].indexOf(cid) < 0) {
- // this parent does not have a child with the given id
- return callback(null, null)
- } else {
- // parent has child
- id_path = factory.lowerResource + '/' + id + '/' + cid
-
- rfactory.get(id_path, function(err, child){
- if(err) {
- if(callback) return callback(err);
- }
- return callback(null, child);
- });
- }
+
+ id_path = factory.lowerResource + '/' + id + '/' + cid
+
+ rfactory.get(id_path, function(err, child){
+ if(err) {
+ if(callback) return callback(err);
+ }
+ return callback(null, child);
+ });
});
}
//
View
10 test/relationship-test.js
@@ -132,6 +132,16 @@ engines.forEach(function (e) {
assert.isNull(err);
assert.equal(obj.user_id, 'pavan');
}
+ },
+ "and when 'Parent.getChild()' is used with an invalid child id": {
+ topic: function (obj) {
+ resources[e].User.getRepository('pavan', 'pants', this.callback);
+ },
+ "should return 404": function (err, obj) {
+ assert.isObject(err);
+ assert.isUndefined(obj);
+ assert.equal(err.status, 404)
+ },
}
}
}

0 comments on commit e483234

Please sign in to comment.
Something went wrong with that request. Please try again.