Skip to content

Commit

Permalink
Merge pull request #491 from benkitzelman/omit-properties
Browse files Browse the repository at this point in the history
omit should return instances populated ids and foreign keys
  • Loading branch information
dxg committed Apr 28, 2014
2 parents 79e7022 + f698dbc commit f9150dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/ChainFind.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function ChainFind(Model, opts) {
} else {
omit = Array.prototype.slice.apply(arguments);
}
this.only(_.difference(Object.keys(Model.properties), omit));
this.only(_.difference(Object.keys(Model.allProperties), omit));
return this;
},
limit: function (limit) {
Expand Down
24 changes: 15 additions & 9 deletions test/integration/model-find-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@ describe("Model.find() chaining", function() {
age : Number
});
Person.hasMany("parents");
Person.hasOne("friend");

ORM.singleton.clear(); // clear cache

return helper.dropSync(Person, function () {
Person.create([{
name : "John",
surname : "Doe",
age : 18
name : "John",
surname : "Doe",
age : 18,
friend_id : 1
}, {
name : "Jane",
surname : "Doe",
age : 20
name : "Jane",
surname : "Doe",
age : 20,
friend_id : 1
}, {
name : "Jane",
surname : "Dean",
age : 18
name : "Jane",
surname : "Dean",
age : 18,
friend_id : 1
}], done);
});
};
Expand Down Expand Up @@ -215,6 +219,8 @@ describe("Model.find() chaining", function() {
Person.find().omit("age", "surname").order("-age").run(function (err, instances) {
should.equal(err, null);
instances.should.have.property("length", 3);
should.exist(instances[0].id);
should.exist(instances[0].friend_id);
instances[0].should.have.property("age", null);
instances[0].should.have.property("surname", null);
instances[0].should.have.property("name", "Jane");
Expand Down

0 comments on commit f9150dc

Please sign in to comment.