不要怂,就是干,撸起袖子干!

Commit 46d6ebfa by José Moreira

Instance.get: following up comments on PR

1 parent f3795742
Showing with 30 additions and 5 deletions
......@@ -182,9 +182,9 @@ module.exports = (function() {
if (options && options.plain && this.options.include && this.options.includeNames.indexOf(key) !== -1) {
if (Array.isArray(this.dataValues[key])) {
return this.dataValues[key].map(function (instance) {
return instance instanceof Instance ? instance.get({plain: options.plain}) : instance;
return instance.get({plain: options.plain});
});
} else if ( this.dataValues[key] instanceof Instance ) {
} else if (this.dataValues[key] instanceof Instance) {
return this.dataValues[key].get({plain: options.plain});
} else {
return this.dataValues[key];
......@@ -210,9 +210,9 @@ module.exports = (function() {
if (options && options.plain && this.options.include && this.options.includeNames.indexOf(_key) !== -1) {
if (Array.isArray(this.dataValues[_key])) {
values[_key] = this.dataValues[_key].map(function (instance) {
return instance instanceof Instance ? instance.get({plain: options.plain}) : instance;
return instance.get({plain: options.plain});
});
} else if ( this.dataValues[_key] instanceof Instance ) {
} else if (this.dataValues[_key] instanceof Instance) {
values[_key] = this.dataValues[_key].get({plain: options.plain});
} else {
values[_key] = this.dataValues[_key];
......
......@@ -1200,7 +1200,7 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
})
})
it('dont return instance that is not defined', function ( done ) {
it("dont return instance that isn't defined", function ( done ) {
var self = this;
self.Project.create({ lovelyUserId: null })
......@@ -1224,6 +1224,31 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
});
it("dont return instances that aren't defined", function ( done ) {
var self = this;
self.User.create({ username: 'cuss' })
.then(function ( user ) {
return self.User.find({
where: {
id: user.id,
},
include: [
{ model: self.Project, as: 'Projects' }
]
})
})
.then(function ( user ) {
var json = user.toJSON();
expect( user.Projects ).to.be.instanceof( Array )
expect( user.Projects ).to.be.length( 0 )
})
.done( done )
.catch( done );
});
it('returns an object containing all values', function(done) {
var user = this.User.build({ username: 'test.user', age: 99, isAdmin: true })
expect(user.toJSON()).to.deep.equal({ username: 'test.user', age: 99, isAdmin: true, id: null })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!