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

Commit 58767fec by Jan Aagaard Meier

Also test associations without alias

1 parent a9bc35d2
...@@ -10,12 +10,13 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() { ...@@ -10,12 +10,13 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
describe("Model.associations", function () { describe("Model.associations", function () {
it("should store all assocations when associting to the same table multiple times", function () { it("should store all assocations when associting to the same table multiple times", function () {
var User = this.sequelize.define('User', {}) var User = this.sequelize.define('User', {})
, Group = this.sequelize.define('Group', {}); , Group = this.sequelize.define('Group', {})
Group.belongsTo(User, { foreignKey: 'primaryGroupId', as: 'primaryUsers' }); Group.belongsTo(User)
Group.belongsTo(User, { foreignKey: 'secondaryGroupId', as: 'secondaryUsers' }); Group.belongsTo(User, { foreignKey: 'primaryGroupId', as: 'primaryUsers' })
Group.belongsTo(User, { foreignKey: 'secondaryGroupId', as: 'secondaryUsers' })
expect(Object.keys(Group.associations)).to.deep.equal(['primaryUsers', 'secondaryUsers']) expect(Object.keys(Group.associations)).to.deep.equal(['Users', 'primaryUsers', 'secondaryUsers'])
}) })
}) })
......
...@@ -14,12 +14,13 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -14,12 +14,13 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
describe("Model.associations", function () { describe("Model.associations", function () {
it("should store all assocations when associting to the same table multiple times", function () { it("should store all assocations when associting to the same table multiple times", function () {
var User = this.sequelize.define('User', {}) var User = this.sequelize.define('User', {})
, Group = this.sequelize.define('Group', {}); , Group = this.sequelize.define('Group', {})
Group.hasMany(User, { foreignKey: 'primaryGroupId', as: 'primaryUsers' }); Group.hasMany(User)
Group.hasMany(User, { foreignKey: 'secondaryGroupId', as: 'secondaryUsers' }); Group.hasMany(User, { foreignKey: 'primaryGroupId', as: 'primaryUsers' })
Group.hasMany(User, { foreignKey: 'secondaryGroupId', as: 'secondaryUsers' })
expect(Object.keys(Group.associations)).to.deep.equal(['primaryUsers', 'secondaryUsers']) expect(Object.keys(Group.associations)).to.deep.equal(['GroupsUsers', 'primaryUsers', 'secondaryUsers'])
}) })
}) })
......
...@@ -10,12 +10,13 @@ describe(Support.getTestDialectTeaser("HasOne"), function() { ...@@ -10,12 +10,13 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
describe("Model.associations", function () { describe("Model.associations", function () {
it("should store all assocations when associting to the same table multiple times", function () { it("should store all assocations when associting to the same table multiple times", function () {
var User = this.sequelize.define('User', {}) var User = this.sequelize.define('User', {})
, Group = this.sequelize.define('Group', {}); , Group = this.sequelize.define('Group', {})
Group.hasOne(User, { foreignKey: 'primaryGroupId', as: 'primaryUsers' }); Group.hasOne(User)
Group.hasOne(User, { foreignKey: 'secondaryGroupId', as: 'secondaryUsers' }); Group.hasOne(User, { foreignKey: 'primaryGroupId', as: 'primaryUsers' })
Group.hasOne(User, { foreignKey: 'secondaryGroupId', as: 'secondaryUsers' })
expect(Object.keys(Group.associations)).to.deep.equal(['primaryUsers', 'secondaryUsers']) expect(Object.keys(Group.associations)).to.deep.equal(['Users', 'primaryUsers', 'secondaryUsers'])
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!