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

Commit cb6a51cb by Mick Hansen

Merge branch 'master' of github.com:sequelize/sequelize

2 parents c749746e 8a3013c5
Showing with 55 additions and 2 deletions
...@@ -184,8 +184,10 @@ module.exports = (function() { ...@@ -184,8 +184,10 @@ module.exports = (function() {
return this.dataValues[key].map(function (instance) { return this.dataValues[key].map(function (instance) {
return instance.get({plain: options.plain}); return instance.get({plain: options.plain});
}); });
} else { } else if (this.dataValues[key] instanceof Instance) {
return this.dataValues[key].get({plain: options.plain}); return this.dataValues[key].get({plain: options.plain});
} else {
return this.dataValues[key];
} }
} }
return this.dataValues[key]; return this.dataValues[key];
...@@ -210,8 +212,10 @@ module.exports = (function() { ...@@ -210,8 +212,10 @@ module.exports = (function() {
values[_key] = this.dataValues[_key].map(function (instance) { values[_key] = this.dataValues[_key].map(function (instance) {
return instance.get({plain: options.plain}); return instance.get({plain: options.plain});
}); });
} else { } else if (this.dataValues[_key] instanceof Instance) {
values[_key] = this.dataValues[_key].get({plain: options.plain}); values[_key] = this.dataValues[_key].get({plain: options.plain});
} else {
values[_key] = this.dataValues[_key];
} }
} else { } else {
values[_key] = this.dataValues[_key]; values[_key] = this.dataValues[_key];
......
...@@ -1200,6 +1200,55 @@ describe(Support.getTestDialectTeaser("DAO"), function () { ...@@ -1200,6 +1200,55 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
}) })
}) })
it("dont return instance that isn't defined", function ( done ) {
var self = this;
self.Project.create({ lovelyUserId: null })
.then(function ( project ) {
return self.Project.find({
where: {
id: project.id,
},
include: [
{ model: self.User, as: 'LovelyUser' }
]
})
})
.then(function ( project ) {
var json = project.toJSON();
expect( json.LovelyUser ).to.be.equal( null )
})
.done( done )
.catch( done );
});
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) { it('returns an object containing all values', function(done) {
var user = this.User.build({ username: 'test.user', age: 99, isAdmin: true }) 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 }) 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!