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

Commit 0a19db54 by Jan Scheurer

Add unit test for updated join table attributes in dobule linked has-many associations

1 parent 338c1e05
Showing with 29 additions and 0 deletions
...@@ -338,6 +338,35 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -338,6 +338,35 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
}) })
}) })
}) })
it('allows to update join table attributes with primary keys other than "id"', function () {
var Article = this.sequelize.define('Article', {aid: {type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true}, title: DataTypes.STRING})
, Label = this.sequelize.define('Label', {lid: {type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true}, text: DataTypes.STRING})
, ArticleHasLabel = this.sequelize.define('ArticleHasLabel', {color: DataTypes.ENUM(["red", "green", "blue"])})
Article.hasMany(Label, {through: ArticleHasLabel})
Label.hasMany(Article, {through: ArticleHasLabel})
return this.sequelize.sync({ force: true }).then(function () {
return Article.create().then(function (article) {
return Label.create({ text: "cheap" }).then(function (label1) {
return Label.create({ text: "steal" }).then(function (label2) {
label2.ArticleHasLabel = {color: "green"}
return article.setLabels([label1, label2]).then(function () {
label1.ArticleHasLabel = {color: "red"}
article.setLabels([label1, label2]).then(function () {
article.getLabels().then(function (labels) {
expect(labels).to.have.length(2)
expect(labels[0].ArticleHasLabel.color).to.equal("red")
expect(labels[1].ArticleHasLabel.color).to.equal("green")
})
})
})
})
})
})
})
})
}) })
describe('addAssociations', function() { describe('addAssociations', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!