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

Commit 93c164bb by Victor Pontis

single linked has many broken when specifying field

1 parent 7bb9c07e
Showing with 36 additions and 1 deletions
...@@ -1476,7 +1476,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1476,7 +1476,9 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
beforeEach(function() { beforeEach(function() {
this.User = this.sequelize.define('User', { name: DataTypes.STRING }); this.User = this.sequelize.define('User', { name: DataTypes.STRING });
this.Project = this.sequelize.define('Project', { name: DataTypes.STRING }); this.Project = this.sequelize.define('Project', { name: DataTypes.STRING });
this.Puppy = this.sequelize.define('Puppy', { breed: DataTypes.STRING });
// doubly linked has many
this.User.hasMany(this.Project, { this.User.hasMany(this.Project, {
through: 'user_projects', through: 'user_projects',
as: 'Projects', as: 'Projects',
...@@ -1493,9 +1495,24 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1493,9 +1495,24 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
name: 'projectId' name: 'projectId'
} }
}); });
// singly linked has many
this.User.hasMany(this.Puppy, {
as: 'Puppies',
foreignKey: {
field: 'user_id',
name: 'userId'
}
});
this.Puppy.belongsTo(this.User, {
foreignKey: {
field: 'user_id',
name: 'userId'
}
});
}); });
it('should correctly get associations', function() { it('should correctly get associations when doubly linked', function() {
var self = this; var self = this;
return this.sequelize.sync({force: true}).then(function() { return this.sequelize.sync({force: true}).then(function() {
return Promise.all([ return Promise.all([
...@@ -1513,6 +1530,24 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1513,6 +1530,24 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
}); });
}); });
it('should correctly get associations when singly linked', function() {
var self = this;
return this.sequelize.sync({force: true}).then(function() {
return Promise.all([
self.User.create({name: 'Matt'}),
self.Puppy.create({breed: 'Terrier'})
]);
}).spread(function (user, puppy) {
return user.addPuppy(puppy).return(user);
}).then(function(user) {
return user.getPuppies();
}).then(function(puppies) {
var puppy = puppies[0];
expect(puppy).to.be.defined;
});
});
it('should be able to handle nested includes properly', function() { it('should be able to handle nested includes properly', function() {
var self = this; var self = this;
this.Group = this.sequelize.define('Group', { groupName: DataTypes.STRING}); this.Group = this.sequelize.define('Group', { groupName: DataTypes.STRING});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!