Find on hasMany scope method
This commit is contained in:
parent
f56cbaa150
commit
704bc965bd
|
@ -938,7 +938,7 @@ AbstractClass.hasMany = function hasMany(anotherClass, params) {
|
|||
anotherClass.find(id, function (err, inst) {
|
||||
if (err) return cb(err);
|
||||
if (!inst) return cb(new Error('Not found'));
|
||||
if (inst[fk] == this.id) {
|
||||
if (inst[fk] && inst[fk].toString() == this.id.toString()) {
|
||||
cb(null, inst);
|
||||
} else {
|
||||
cb(new Error('Permission denied'));
|
||||
|
|
|
@ -92,6 +92,29 @@ describe('relations', function() {
|
|||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('should find scoped record', function(done) {
|
||||
var id;
|
||||
Book.create(function(err, book) {
|
||||
book.chapters.create({name: 'a'}, function(err, ch) {
|
||||
id = ch.id;
|
||||
book.chapters.create({name: 'z'}, function() {
|
||||
book.chapters.create({name: 'c'}, function() {
|
||||
fetch(book);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function fetch(book) {
|
||||
book.chapters.find(id, function(err, ch) {
|
||||
should.not.exist(err);
|
||||
should.exist(ch);
|
||||
ch.id.should.equal(id);
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('belongsTo', function() {
|
||||
|
|
Loading…
Reference in New Issue