From 6800fbddfa9da8d781a1d3fdc2f611d226e9e8e4 Mon Sep 17 00:00:00 2001 From: Alyx Date: Wed, 31 Jan 2024 13:18:24 +0100 Subject: [PATCH] feat!: make generated association names lowerCamelCase by default (#16514) Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com> --- packages/core/src/associations/helpers.ts | 7 +- packages/core/src/utils/object.ts | 16 - packages/core/src/utils/string.ts | 13 +- .../associations/belongs-to-many.test.js | 486 ++++++++---------- .../associations/belongs-to.test.js | 24 +- .../integration/associations/has-many.test.js | 47 +- .../integration/associations/has-one.test.js | 26 +- .../multiple-level-filters.test.js | 36 +- .../integration/data-types/methods.test.ts | 1 + .../dialects/mssql/regressions.test.js | 12 +- .../integration/dialects/postgres/dao.test.js | 10 +- .../core/test/integration/include.test.js | 146 +++--- .../test/integration/include/findAll.test.js | 262 +++++----- .../include/findAndCountAll.test.js | 28 +- .../test/integration/include/findOne.test.js | 6 +- .../test/integration/include/limit.test.js | 4 +- .../test/integration/include/schema.test.js | 153 +++--- .../test/integration/include/separate.test.js | 10 +- packages/core/test/integration/model.test.js | 16 +- .../model/bulk-create/include.test.js | 90 ++-- .../core/test/integration/model/count.test.js | 6 +- .../integration/model/create/include.test.js | 60 +-- .../test/integration/model/findAll.test.js | 24 +- .../integration/model/findAll/group.test.js | 28 +- .../model/findAll/separate.test.js | 128 +++-- .../test/integration/model/findOne.test.js | 28 +- .../integration/model/findOrBuild.test.js | 4 +- .../test/integration/model/paranoid.test.js | 10 +- .../model/scope/associations.test.js | 8 +- .../integration/model/scope/count.test.js | 2 +- .../core/test/integration/model/sync.test.js | 6 +- .../query-interface/changeColumn.test.js | 6 +- .../test/integration/sequelize/drop.test.ts | 8 +- .../integration/sequelize/truncate.test.ts | 20 +- .../unit/associations/association.test.ts | 8 +- .../unit/associations/belongs-to-many.test.ts | 102 ++-- .../test/unit/associations/belongs-to.test.ts | 20 +- .../associations/dont-modify-options.test.js | 8 +- .../test/unit/associations/has-many.test.ts | 10 + .../test/unit/associations/has-one.test.ts | 22 +- .../unit/query-generator/select-query.test.ts | 159 ++++-- .../core/test/unit/sql/generateJoin.test.js | 10 +- packages/core/test/unit/sql/order.test.js | 2 + packages/core/test/unit/sql/select.test.js | 42 +- packages/core/test/unit/utils/utils.test.ts | 21 +- 45 files changed, 1082 insertions(+), 1053 deletions(-) diff --git a/packages/core/src/associations/helpers.ts b/packages/core/src/associations/helpers.ts index a61e12949b6a..f311b3c348d0 100644 --- a/packages/core/src/associations/helpers.ts +++ b/packages/core/src/associations/helpers.ts @@ -290,8 +290,11 @@ export function normalizeBaseAssociationOptions = { [P in keyof T]: Exclude }; export function removeUndefined(val: T): NoUndefinedField { diff --git a/packages/core/src/utils/string.ts b/packages/core/src/utils/string.ts index a8ddd624cf53..5252e766caec 100644 --- a/packages/core/src/utils/string.ts +++ b/packages/core/src/utils/string.ts @@ -1,5 +1,6 @@ import NodeUtil from 'node:util'; import * as _inflection from 'inflection'; +import lowerFirst from 'lodash/lowerFirst'; import type { IndexOptions, TableName } from '../dialects/abstract/query-interface.js'; import { BaseSqlExpression } from '../expression-builders/base-sql-expression.js'; @@ -14,18 +15,8 @@ export function useInflection(newInflection: Inflection) { /* String utils */ -export function camelizeIf(str: string, condition: boolean): string { - let result = str; - - if (condition) { - result = camelize(str); - } - - return result; -} - export function camelize(str: string): string { - return str.trim().replaceAll(/[-_\s]+(.)?/g, (match, c) => c.toUpperCase()); + return lowerFirst(str.trim()).replaceAll(/[-_\s]+(.)?/g, (match, c) => c.toUpperCase()); } export function underscoredIf(str: string, condition: boolean): string { diff --git a/packages/core/test/integration/associations/belongs-to-many.test.js b/packages/core/test/integration/associations/belongs-to-many.test.js index cb62e7c95cd3..da7847901c92 100644 --- a/packages/core/test/integration/associations/belongs-to-many.test.js +++ b/packages/core/test/integration/associations/belongs-to-many.test.js @@ -19,8 +19,8 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { this.User = this.sequelize.define('User', { username: DataTypes.STRING }); this.Task = this.sequelize.define('Task', { title: DataTypes.STRING, active: DataTypes.BOOLEAN }); - this.User.belongsToMany(this.Task, { through: 'UserTasks' }); - this.Task.belongsToMany(this.User, { through: 'UserTasks' }); + this.User.belongsToMany(this.Task, { through: 'UserTasks', as: 'Tasks', inverse: 'Users' }); + this.Task.belongsToMany(this.User, { through: 'UserTasks', as: 'Users', inverse: 'Tasks' }); await this.sequelize.sync({ force: true }); @@ -145,8 +145,8 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { const Task = this.Task; const User = this.User; - Task.hasMany(Label); - Label.belongsTo(Task); + Task.hasMany(Label, { as: 'Labels' }); + Label.belongsTo(Task, { as: 'Tasks' }); await Label.sync({ force: true }); @@ -178,8 +178,8 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { data: DataTypes.INTEGER, }).schema('acme', '_'); - AcmeUser.belongsToMany(AcmeProject, { through: AcmeProjectUsers }); - AcmeProject.belongsToMany(AcmeUser, { through: AcmeProjectUsers }); + AcmeUser.belongsToMany(AcmeProject, { through: AcmeProjectUsers, as: 'Projects', inverse: 'Users' }); + AcmeProject.belongsToMany(AcmeUser, { through: AcmeProjectUsers, as: 'Users', inverse: 'Projects' }); await this.sequelize.createSchema('acme'); await Promise.all([ @@ -280,33 +280,36 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { tableName: 'tbl_user_has_group', }); - User.belongsToMany(Group, { through: User_has_Group }); - Group.belongsToMany(User, { through: User_has_Group }); + User.belongsToMany(Group, { through: User_has_Group, as: 'Groups', inverse: 'Users' }); + Group.belongsToMany(User, { through: User_has_Group, as: 'Users', inverse: 'Groups' }); await this.sequelize.sync({ force: true }); const [user0, group] = await Promise.all([User.create(), Group.create()]); await user0.addGroup(group); - const [user, users] = await Promise.all([User.findOne({ - where: {}, - include: [Group], - }), User.findAll({ - include: [Group], - })]); + const [user, users] = await Promise.all([ + User.findOne({ + where: {}, + include: [Group], + }), + User.findAll({ + include: [Group], + }), + ]); expect(user.Groups.length).to.equal(1); - expect(user.Groups[0].User_has_Group.UserUserSecondId).to.be.ok; + expect(user.Groups[0].User_has_Group.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(user.Groups[0].User_has_Group.UserUserSecondId).to.deep.equal(user.userSecondId); + expect(user.Groups[0].User_has_Group.userUserSecondId).to.deep.equal(user.userSecondId); } else { - expect(user.Groups[0].User_has_Group.UserUserSecondId).to.equal(user.userSecondId); + expect(user.Groups[0].User_has_Group.userUserSecondId).to.equal(user.userSecondId); } - expect(user.Groups[0].User_has_Group.GroupGroupSecondId).to.be.ok; + expect(user.Groups[0].User_has_Group.groupGroupSecondId).to.be.ok; if (dialect === 'db2') { - expect(user.Groups[0].User_has_Group.GroupGroupSecondId).to.deep.equal(user.Groups[0].groupSecondId); + expect(user.Groups[0].User_has_Group.groupGroupSecondId).to.deep.equal(user.Groups[0].groupSecondId); } else { - expect(user.Groups[0].User_has_Group.GroupGroupSecondId).to.equal(user.Groups[0].groupSecondId); + expect(user.Groups[0].User_has_Group.groupGroupSecondId).to.equal(user.Groups[0].groupSecondId); } expect(users.length).to.equal(1); @@ -362,7 +365,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ], }); - User.belongsToMany(Group, { through: 'usergroups', sourceKey: 'userSecondId', targetKey: 'groupSecondId' }); + User.belongsToMany(Group, { through: 'usergroups', sourceKey: 'userSecondId', targetKey: 'groupSecondId', as: 'Groups' }); await this.sequelize.sync({ force: true }); const [user1, user2, group1, group2] = await Promise.all([User.create(), User.create(), Group.create(), Group.create()]); @@ -378,63 +381,63 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { expect(users.length).to.equal(2); expect(users[0].Groups.length).to.equal(1); expect(users[1].Groups.length).to.equal(1); - expect(users[0].Groups[0].usergroups.UserUserSecondId).to.be.ok; + expect(users[0].Groups[0].usergroups.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(users[0].Groups[0].usergroups.UserUserSecondId).to.deep.equal(users[0].userSecondId); + expect(users[0].Groups[0].usergroups.userUserSecondId).to.deep.equal(users[0].userSecondId); } else { - expect(users[0].Groups[0].usergroups.UserUserSecondId).to.equal(users[0].userSecondId); + expect(users[0].Groups[0].usergroups.userUserSecondId).to.equal(users[0].userSecondId); } - expect(users[0].Groups[0].usergroups.GroupGroupSecondId).to.be.ok; + expect(users[0].Groups[0].usergroups.groupGroupSecondId).to.be.ok; if (dialect === 'db2') { - expect(users[0].Groups[0].usergroups.GroupGroupSecondId).to.deep.equal(users[0].Groups[0].groupSecondId); + expect(users[0].Groups[0].usergroups.groupGroupSecondId).to.deep.equal(users[0].Groups[0].groupSecondId); } else { - expect(users[0].Groups[0].usergroups.GroupGroupSecondId).to.equal(users[0].Groups[0].groupSecondId); + expect(users[0].Groups[0].usergroups.groupGroupSecondId).to.equal(users[0].Groups[0].groupSecondId); } - expect(users[1].Groups[0].usergroups.UserUserSecondId).to.be.ok; + expect(users[1].Groups[0].usergroups.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(users[1].Groups[0].usergroups.UserUserSecondId).to.deep.equal(users[1].userSecondId); + expect(users[1].Groups[0].usergroups.userUserSecondId).to.deep.equal(users[1].userSecondId); } else { - expect(users[1].Groups[0].usergroups.UserUserSecondId).to.equal(users[1].userSecondId); + expect(users[1].Groups[0].usergroups.userUserSecondId).to.equal(users[1].userSecondId); } - expect(users[1].Groups[0].usergroups.GroupGroupSecondId).to.be.ok; + expect(users[1].Groups[0].usergroups.groupGroupSecondId).to.be.ok; if (dialect === 'db2') { - expect(users[1].Groups[0].usergroups.GroupGroupSecondId).to.deep.equal(users[1].Groups[0].groupSecondId); + expect(users[1].Groups[0].usergroups.groupGroupSecondId).to.deep.equal(users[1].Groups[0].groupSecondId); } else { - expect(users[1].Groups[0].usergroups.GroupGroupSecondId).to.equal(users[1].Groups[0].groupSecondId); + expect(users[1].Groups[0].usergroups.groupGroupSecondId).to.equal(users[1].Groups[0].groupSecondId); } expect(groups.length).to.equal(2); - expect(groups[0].Users.length).to.equal(1); - expect(groups[1].Users.length).to.equal(1); - expect(groups[0].Users[0].usergroups.GroupGroupSecondId).to.be.ok; + expect(groups[0].users.length).to.equal(1); + expect(groups[1].users.length).to.equal(1); + expect(groups[0].users[0].usergroups.groupGroupSecondId).to.be.ok; if (dialect === 'db2') { - expect(groups[0].Users[0].usergroups.GroupGroupSecondId).to.deep.equal(groups[0].groupSecondId); + expect(groups[0].users[0].usergroups.groupGroupSecondId).to.deep.equal(groups[0].groupSecondId); } else { - expect(groups[0].Users[0].usergroups.GroupGroupSecondId).to.equal(groups[0].groupSecondId); + expect(groups[0].users[0].usergroups.groupGroupSecondId).to.equal(groups[0].groupSecondId); } - expect(groups[0].Users[0].usergroups.UserUserSecondId).to.be.ok; + expect(groups[0].users[0].usergroups.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(groups[0].Users[0].usergroups.UserUserSecondId).to.deep.equal(groups[0].Users[0].userSecondId); + expect(groups[0].users[0].usergroups.userUserSecondId).to.deep.equal(groups[0].users[0].userSecondId); } else { - expect(groups[0].Users[0].usergroups.UserUserSecondId).to.equal(groups[0].Users[0].userSecondId); + expect(groups[0].users[0].usergroups.userUserSecondId).to.equal(groups[0].users[0].userSecondId); } - expect(groups[1].Users[0].usergroups.GroupGroupSecondId).to.be.ok; + expect(groups[1].users[0].usergroups.groupGroupSecondId).to.be.ok; if (dialect === 'db2') { - expect(groups[1].Users[0].usergroups.GroupGroupSecondId).to.deep.equal(groups[1].groupSecondId); + expect(groups[1].users[0].usergroups.groupGroupSecondId).to.deep.equal(groups[1].groupSecondId); } else { - expect(groups[1].Users[0].usergroups.GroupGroupSecondId).to.equal(groups[1].groupSecondId); + expect(groups[1].users[0].usergroups.groupGroupSecondId).to.equal(groups[1].groupSecondId); } - expect(groups[1].Users[0].usergroups.UserUserSecondId).to.be.ok; + expect(groups[1].users[0].usergroups.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(groups[1].Users[0].usergroups.UserUserSecondId).to.deep.equal(groups[1].Users[0].userSecondId); + expect(groups[1].users[0].usergroups.userUserSecondId).to.deep.equal(groups[1].users[0].userSecondId); } else { - expect(groups[1].Users[0].usergroups.UserUserSecondId).to.equal(groups[1].Users[0].userSecondId); + expect(groups[1].users[0].usergroups.userUserSecondId).to.equal(groups[1].users[0].userSecondId); } }); @@ -496,65 +499,65 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { })]); expect(users.length).to.equal(2); - expect(users[0].Groups.length).to.equal(1); - expect(users[1].Groups.length).to.equal(1); - expect(users[0].Groups[0].usergroups.UserUserSecondId).to.be.ok; + expect(users[0].groups.length).to.equal(1); + expect(users[1].groups.length).to.equal(1); + expect(users[0].groups[0].usergroups.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(users[0].Groups[0].usergroups.UserUserSecondId).to.deep.equal(users[0].userSecondId); + expect(users[0].groups[0].usergroups.userUserSecondId).to.deep.equal(users[0].userSecondId); } else { - expect(users[0].Groups[0].usergroups.UserUserSecondId).to.equal(users[0].userSecondId); + expect(users[0].groups[0].usergroups.userUserSecondId).to.equal(users[0].userSecondId); } - expect(users[0].Groups[0].usergroups.GroupId).to.be.ok; + expect(users[0].groups[0].usergroups.groupId).to.be.ok; if (dialect === 'db2') { - expect(users[0].Groups[0].usergroups.GroupId).to.deep.equal(users[0].Groups[0].id); + expect(users[0].groups[0].usergroups.groupId).to.deep.equal(users[0].groups[0].id); } else { - expect(users[0].Groups[0].usergroups.GroupId).to.equal(users[0].Groups[0].id); + expect(users[0].groups[0].usergroups.groupId).to.equal(users[0].groups[0].id); } - expect(users[1].Groups[0].usergroups.UserUserSecondId).to.be.ok; + expect(users[1].groups[0].usergroups.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(users[1].Groups[0].usergroups.UserUserSecondId).to.deep.equal(users[1].userSecondId); + expect(users[1].groups[0].usergroups.userUserSecondId).to.deep.equal(users[1].userSecondId); } else { - expect(users[1].Groups[0].usergroups.UserUserSecondId).to.equal(users[1].userSecondId); + expect(users[1].groups[0].usergroups.userUserSecondId).to.equal(users[1].userSecondId); } - expect(users[1].Groups[0].usergroups.GroupId).to.be.ok; + expect(users[1].groups[0].usergroups.groupId).to.be.ok; if (dialect === 'db2') { - expect(users[1].Groups[0].usergroups.GroupId).to.deep.equal(users[1].Groups[0].id); + expect(users[1].groups[0].usergroups.groupId).to.deep.equal(users[1].groups[0].id); } else { - expect(users[1].Groups[0].usergroups.GroupId).to.equal(users[1].Groups[0].id); + expect(users[1].groups[0].usergroups.groupId).to.equal(users[1].groups[0].id); } expect(groups.length).to.equal(2); - expect(groups[0].Users.length).to.equal(1); - expect(groups[1].Users.length).to.equal(1); - expect(groups[0].Users[0].usergroups.GroupId).to.be.ok; + expect(groups[0].users.length).to.equal(1); + expect(groups[1].users.length).to.equal(1); + expect(groups[0].users[0].usergroups.groupId).to.be.ok; if (dialect === 'db2') { - expect(groups[0].Users[0].usergroups.GroupId).to.deep.equal(groups[0].id); + expect(groups[0].users[0].usergroups.groupId).to.deep.equal(groups[0].id); } else { - expect(groups[0].Users[0].usergroups.GroupId).to.equal(groups[0].id); + expect(groups[0].users[0].usergroups.groupId).to.equal(groups[0].id); } - expect(groups[0].Users[0].usergroups.UserUserSecondId).to.be.ok; + expect(groups[0].users[0].usergroups.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(groups[0].Users[0].usergroups.UserUserSecondId).to.deep.equal(groups[0].Users[0].userSecondId); + expect(groups[0].users[0].usergroups.userUserSecondId).to.deep.equal(groups[0].users[0].userSecondId); } else { - expect(groups[0].Users[0].usergroups.UserUserSecondId).to.equal(groups[0].Users[0].userSecondId); + expect(groups[0].users[0].usergroups.userUserSecondId).to.equal(groups[0].users[0].userSecondId); } - expect(groups[1].Users[0].usergroups.GroupId).to.be.ok; + expect(groups[1].users[0].usergroups.groupId).to.be.ok; if (dialect === 'db2') { - expect(groups[1].Users[0].usergroups.GroupId).to.deep.equal(groups[1].id); + expect(groups[1].users[0].usergroups.groupId).to.deep.equal(groups[1].id); } else { - expect(groups[1].Users[0].usergroups.GroupId).to.equal(groups[1].id); + expect(groups[1].users[0].usergroups.groupId).to.equal(groups[1].id); } - expect(groups[1].Users[0].usergroups.UserUserSecondId).to.be.ok; + expect(groups[1].users[0].usergroups.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(groups[1].Users[0].usergroups.UserUserSecondId).to.deep.equal(groups[1].Users[0].userSecondId); + expect(groups[1].users[0].usergroups.userUserSecondId).to.deep.equal(groups[1].users[0].userSecondId); } else { - expect(groups[1].Users[0].usergroups.UserUserSecondId).to.equal(groups[1].Users[0].userSecondId); + expect(groups[1].users[0].usergroups.userUserSecondId).to.equal(groups[1].users[0].userSecondId); } }); @@ -607,8 +610,8 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ], }); - User.belongsToMany(Group, { through: 'usergroups', sourceKey: 'userSecondId', targetKey: 'groupSecondId' }); - Group.belongsToMany(User, { through: 'usergroups', sourceKey: 'groupSecondId', targetKey: 'userSecondId' }); + User.belongsToMany(Group, { through: 'usergroups', sourceKey: 'userSecondId', targetKey: 'groupSecondId', as: 'Groups', inverse: 'Users' }); + Group.belongsToMany(User, { through: 'usergroups', sourceKey: 'groupSecondId', targetKey: 'userSecondId', as: 'Users', inverse: 'Groups' }); await this.sequelize.sync({ force: true }); const [user1, user2, group1, group2] = await Promise.all([User.create(), User.create(), Group.create(), Group.create()]); @@ -624,63 +627,63 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { expect(users.length).to.equal(2); expect(users[0].Groups.length).to.equal(1); expect(users[1].Groups.length).to.equal(1); - expect(users[0].Groups[0].usergroups.UserUserSecondId).to.be.ok; + expect(users[0].Groups[0].usergroups.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(users[0].Groups[0].usergroups.UserUserSecondId).to.deep.equal(users[0].userSecondId); + expect(users[0].Groups[0].usergroups.userUserSecondId).to.deep.equal(users[0].userSecondId); } else { - expect(users[0].Groups[0].usergroups.UserUserSecondId).to.equal(users[0].userSecondId); + expect(users[0].Groups[0].usergroups.userUserSecondId).to.equal(users[0].userSecondId); } - expect(users[0].Groups[0].usergroups.GroupGroupSecondId).to.be.ok; + expect(users[0].Groups[0].usergroups.groupGroupSecondId).to.be.ok; if (dialect === 'db2') { - expect(users[0].Groups[0].usergroups.GroupGroupSecondId).to.deep.equal(users[0].Groups[0].groupSecondId); + expect(users[0].Groups[0].usergroups.groupGroupSecondId).to.deep.equal(users[0].Groups[0].groupSecondId); } else { - expect(users[0].Groups[0].usergroups.GroupGroupSecondId).to.equal(users[0].Groups[0].groupSecondId); + expect(users[0].Groups[0].usergroups.groupGroupSecondId).to.equal(users[0].Groups[0].groupSecondId); } - expect(users[1].Groups[0].usergroups.UserUserSecondId).to.be.ok; + expect(users[1].Groups[0].usergroups.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(users[1].Groups[0].usergroups.UserUserSecondId).to.deep.equal(users[1].userSecondId); + expect(users[1].Groups[0].usergroups.userUserSecondId).to.deep.equal(users[1].userSecondId); } else { - expect(users[1].Groups[0].usergroups.UserUserSecondId).to.equal(users[1].userSecondId); + expect(users[1].Groups[0].usergroups.userUserSecondId).to.equal(users[1].userSecondId); } - expect(users[1].Groups[0].usergroups.GroupGroupSecondId).to.be.ok; + expect(users[1].Groups[0].usergroups.groupGroupSecondId).to.be.ok; if (dialect === 'db2') { - expect(users[1].Groups[0].usergroups.GroupGroupSecondId).to.deep.equal(users[1].Groups[0].groupSecondId); + expect(users[1].Groups[0].usergroups.groupGroupSecondId).to.deep.equal(users[1].Groups[0].groupSecondId); } else { - expect(users[1].Groups[0].usergroups.GroupGroupSecondId).to.equal(users[1].Groups[0].groupSecondId); + expect(users[1].Groups[0].usergroups.groupGroupSecondId).to.equal(users[1].Groups[0].groupSecondId); } expect(groups.length).to.equal(2); expect(groups[0].Users.length).to.equal(1); expect(groups[1].Users.length).to.equal(1); - expect(groups[0].Users[0].usergroups.GroupGroupSecondId).to.be.ok; + expect(groups[0].Users[0].usergroups.groupGroupSecondId).to.be.ok; if (dialect === 'db2') { - expect(groups[0].Users[0].usergroups.GroupGroupSecondId).to.deep.equal(groups[0].groupSecondId); + expect(groups[0].Users[0].usergroups.groupGroupSecondId).to.deep.equal(groups[0].groupSecondId); } else { - expect(groups[0].Users[0].usergroups.GroupGroupSecondId).to.equal(groups[0].groupSecondId); + expect(groups[0].Users[0].usergroups.groupGroupSecondId).to.equal(groups[0].groupSecondId); } - expect(groups[0].Users[0].usergroups.UserUserSecondId).to.be.ok; + expect(groups[0].Users[0].usergroups.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(groups[0].Users[0].usergroups.UserUserSecondId).to.deep.equal(groups[0].Users[0].userSecondId); + expect(groups[0].Users[0].usergroups.userUserSecondId).to.deep.equal(groups[0].Users[0].userSecondId); } else { - expect(groups[0].Users[0].usergroups.UserUserSecondId).to.equal(groups[0].Users[0].userSecondId); + expect(groups[0].Users[0].usergroups.userUserSecondId).to.equal(groups[0].Users[0].userSecondId); } - expect(groups[1].Users[0].usergroups.GroupGroupSecondId).to.be.ok; + expect(groups[1].Users[0].usergroups.groupGroupSecondId).to.be.ok; if (dialect === 'db2') { - expect(groups[1].Users[0].usergroups.GroupGroupSecondId).to.deep.equal(groups[1].groupSecondId); + expect(groups[1].Users[0].usergroups.groupGroupSecondId).to.deep.equal(groups[1].groupSecondId); } else { - expect(groups[1].Users[0].usergroups.GroupGroupSecondId).to.equal(groups[1].groupSecondId); + expect(groups[1].Users[0].usergroups.groupGroupSecondId).to.equal(groups[1].groupSecondId); } - expect(groups[1].Users[0].usergroups.UserUserSecondId).to.be.ok; + expect(groups[1].Users[0].usergroups.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(groups[1].Users[0].usergroups.UserUserSecondId).to.deep.equal(groups[1].Users[0].userSecondId); + expect(groups[1].Users[0].usergroups.userUserSecondId).to.deep.equal(groups[1].Users[0].userSecondId); } else { - expect(groups[1].Users[0].usergroups.UserUserSecondId).to.equal(groups[1].Users[0].userSecondId); + expect(groups[1].Users[0].usergroups.userUserSecondId).to.equal(groups[1].Users[0].userSecondId); } }); @@ -738,7 +741,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { indexes: [ { unique: true, - fields: ['UserUserSecondId', 'GroupGroupSecondId'], + fields: ['userUserSecondId', 'groupGroupSecondId'], name: 'UserHasGroup_Second_Unique', }, ], @@ -758,65 +761,65 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { })]); expect(users.length).to.equal(2); - expect(users[0].Groups.length).to.equal(1); - expect(users[1].Groups.length).to.equal(1); - expect(users[0].Groups[0].User_has_Group.UserUserSecondId).to.be.ok; + expect(users[0].groups.length).to.equal(1); + expect(users[1].groups.length).to.equal(1); + expect(users[0].groups[0].User_has_Group.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(users[0].Groups[0].User_has_Group.UserUserSecondId).to.deep.equal(users[0].userSecondId); + expect(users[0].groups[0].User_has_Group.userUserSecondId).to.deep.equal(users[0].userSecondId); } else { - expect(users[0].Groups[0].User_has_Group.UserUserSecondId).to.equal(users[0].userSecondId); + expect(users[0].groups[0].User_has_Group.userUserSecondId).to.equal(users[0].userSecondId); } - expect(users[0].Groups[0].User_has_Group.GroupGroupSecondId).to.be.ok; + expect(users[0].groups[0].User_has_Group.groupGroupSecondId).to.be.ok; if (dialect === 'db2') { - expect(users[0].Groups[0].User_has_Group.GroupGroupSecondId).to.deep.equal(users[0].Groups[0].groupSecondId); + expect(users[0].groups[0].User_has_Group.groupGroupSecondId).to.deep.equal(users[0].groups[0].groupSecondId); } else { - expect(users[0].Groups[0].User_has_Group.GroupGroupSecondId).to.equal(users[0].Groups[0].groupSecondId); + expect(users[0].groups[0].User_has_Group.groupGroupSecondId).to.equal(users[0].groups[0].groupSecondId); } - expect(users[1].Groups[0].User_has_Group.UserUserSecondId).to.be.ok; + expect(users[1].groups[0].User_has_Group.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(users[1].Groups[0].User_has_Group.UserUserSecondId).to.deep.equal(users[1].userSecondId); + expect(users[1].groups[0].User_has_Group.userUserSecondId).to.deep.equal(users[1].userSecondId); } else { - expect(users[1].Groups[0].User_has_Group.UserUserSecondId).to.equal(users[1].userSecondId); + expect(users[1].groups[0].User_has_Group.userUserSecondId).to.equal(users[1].userSecondId); } - expect(users[1].Groups[0].User_has_Group.GroupGroupSecondId).to.be.ok; + expect(users[1].groups[0].User_has_Group.groupGroupSecondId).to.be.ok; if (dialect === 'db2') { - expect(users[1].Groups[0].User_has_Group.GroupGroupSecondId).to.deep.equal(users[1].Groups[0].groupSecondId); + expect(users[1].groups[0].User_has_Group.groupGroupSecondId).to.deep.equal(users[1].groups[0].groupSecondId); } else { - expect(users[1].Groups[0].User_has_Group.GroupGroupSecondId).to.equal(users[1].Groups[0].groupSecondId); + expect(users[1].groups[0].User_has_Group.groupGroupSecondId).to.equal(users[1].groups[0].groupSecondId); } expect(groups.length).to.equal(2); - expect(groups[0].Users.length).to.equal(1); - expect(groups[1].Users.length).to.equal(1); - expect(groups[0].Users[0].User_has_Group.GroupGroupSecondId).to.be.ok; + expect(groups[0].users.length).to.equal(1); + expect(groups[1].users.length).to.equal(1); + expect(groups[0].users[0].User_has_Group.groupGroupSecondId).to.be.ok; if (dialect === 'db2') { - expect(groups[0].Users[0].User_has_Group.GroupGroupSecondId).to.deep.equal(groups[0].groupSecondId); + expect(groups[0].users[0].User_has_Group.groupGroupSecondId).to.deep.equal(groups[0].groupSecondId); } else { - expect(groups[0].Users[0].User_has_Group.GroupGroupSecondId).to.equal(groups[0].groupSecondId); + expect(groups[0].users[0].User_has_Group.groupGroupSecondId).to.equal(groups[0].groupSecondId); } - expect(groups[0].Users[0].User_has_Group.UserUserSecondId).to.be.ok; + expect(groups[0].users[0].User_has_Group.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(groups[0].Users[0].User_has_Group.UserUserSecondId).to.deep.equal(groups[0].Users[0].userSecondId); + expect(groups[0].users[0].User_has_Group.userUserSecondId).to.deep.equal(groups[0].users[0].userSecondId); } else { - expect(groups[0].Users[0].User_has_Group.UserUserSecondId).to.equal(groups[0].Users[0].userSecondId); + expect(groups[0].users[0].User_has_Group.userUserSecondId).to.equal(groups[0].users[0].userSecondId); } - expect(groups[1].Users[0].User_has_Group.GroupGroupSecondId).to.be.ok; + expect(groups[1].users[0].User_has_Group.groupGroupSecondId).to.be.ok; if (dialect === 'db2') { - expect(groups[1].Users[0].User_has_Group.GroupGroupSecondId).to.deep.equal(groups[1].groupSecondId); + expect(groups[1].users[0].User_has_Group.groupGroupSecondId).to.deep.equal(groups[1].groupSecondId); } else { - expect(groups[1].Users[0].User_has_Group.GroupGroupSecondId).to.equal(groups[1].groupSecondId); + expect(groups[1].users[0].User_has_Group.groupGroupSecondId).to.equal(groups[1].groupSecondId); } - expect(groups[1].Users[0].User_has_Group.UserUserSecondId).to.be.ok; + expect(groups[1].users[0].User_has_Group.userUserSecondId).to.be.ok; if (dialect === 'db2') { - expect(groups[1].Users[0].User_has_Group.UserUserSecondId).to.deep.equal(groups[1].Users[0].userSecondId); + expect(groups[1].users[0].User_has_Group.userUserSecondId).to.deep.equal(groups[1].users[0].userSecondId); } else { - expect(groups[1].Users[0].User_has_Group.UserUserSecondId).to.equal(groups[1].Users[0].userSecondId); + expect(groups[1].users[0].User_has_Group.userUserSecondId).to.equal(groups[1].users[0].userSecondId); } }); @@ -957,65 +960,65 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { })]); expect(users.length).to.equal(2); - expect(users[0].Groups.length).to.equal(1); - expect(users[1].Groups.length).to.equal(1); - expect(users[0].Groups[0].usergroups.userId2).to.be.ok; + expect(users[0].groups.length).to.equal(1); + expect(users[1].groups.length).to.equal(1); + expect(users[0].groups[0].usergroups.userId2).to.be.ok; if (dialect === 'db2') { - expect(users[0].Groups[0].usergroups.userId2).to.deep.equal(users[0].userSecondId); + expect(users[0].groups[0].usergroups.userId2).to.deep.equal(users[0].userSecondId); } else { - expect(users[0].Groups[0].usergroups.userId2).to.equal(users[0].userSecondId); + expect(users[0].groups[0].usergroups.userId2).to.equal(users[0].userSecondId); } - expect(users[0].Groups[0].usergroups.groupId2).to.be.ok; + expect(users[0].groups[0].usergroups.groupId2).to.be.ok; if (dialect === 'db2') { - expect(users[0].Groups[0].usergroups.groupId2).to.deep.equal(users[0].Groups[0].groupSecondId); + expect(users[0].groups[0].usergroups.groupId2).to.deep.equal(users[0].groups[0].groupSecondId); } else { - expect(users[0].Groups[0].usergroups.groupId2).to.equal(users[0].Groups[0].groupSecondId); + expect(users[0].groups[0].usergroups.groupId2).to.equal(users[0].groups[0].groupSecondId); } - expect(users[1].Groups[0].usergroups.userId2).to.be.ok; + expect(users[1].groups[0].usergroups.userId2).to.be.ok; if (dialect === 'db2') { - expect(users[1].Groups[0].usergroups.userId2).to.deep.equal(users[1].userSecondId); + expect(users[1].groups[0].usergroups.userId2).to.deep.equal(users[1].userSecondId); } else { - expect(users[1].Groups[0].usergroups.userId2).to.equal(users[1].userSecondId); + expect(users[1].groups[0].usergroups.userId2).to.equal(users[1].userSecondId); } - expect(users[1].Groups[0].usergroups.groupId2).to.be.ok; + expect(users[1].groups[0].usergroups.groupId2).to.be.ok; if (dialect === 'db2') { - expect(users[1].Groups[0].usergroups.groupId2).to.deep.equal(users[1].Groups[0].groupSecondId); + expect(users[1].groups[0].usergroups.groupId2).to.deep.equal(users[1].groups[0].groupSecondId); } else { - expect(users[1].Groups[0].usergroups.groupId2).to.equal(users[1].Groups[0].groupSecondId); + expect(users[1].groups[0].usergroups.groupId2).to.equal(users[1].groups[0].groupSecondId); } expect(groups.length).to.equal(2); - expect(groups[0].Users.length).to.equal(1); - expect(groups[1].Users.length).to.equal(1); - expect(groups[0].Users[0].usergroups.groupId2).to.be.ok; + expect(groups[0].users.length).to.equal(1); + expect(groups[1].users.length).to.equal(1); + expect(groups[0].users[0].usergroups.groupId2).to.be.ok; if (dialect === 'db2') { - expect(groups[0].Users[0].usergroups.groupId2).to.deep.equal(groups[0].groupSecondId); + expect(groups[0].users[0].usergroups.groupId2).to.deep.equal(groups[0].groupSecondId); } else { - expect(groups[0].Users[0].usergroups.groupId2).to.equal(groups[0].groupSecondId); + expect(groups[0].users[0].usergroups.groupId2).to.equal(groups[0].groupSecondId); } - expect(groups[0].Users[0].usergroups.userId2).to.be.ok; + expect(groups[0].users[0].usergroups.userId2).to.be.ok; if (dialect === 'db2') { - expect(groups[0].Users[0].usergroups.userId2).to.deep.equal(groups[0].Users[0].userSecondId); + expect(groups[0].users[0].usergroups.userId2).to.deep.equal(groups[0].users[0].userSecondId); } else { - expect(groups[0].Users[0].usergroups.userId2).to.equal(groups[0].Users[0].userSecondId); + expect(groups[0].users[0].usergroups.userId2).to.equal(groups[0].users[0].userSecondId); } - expect(groups[1].Users[0].usergroups.groupId2).to.be.ok; + expect(groups[1].users[0].usergroups.groupId2).to.be.ok; if (dialect === 'db2') { - expect(groups[1].Users[0].usergroups.groupId2).to.deep.equal(groups[1].groupSecondId); + expect(groups[1].users[0].usergroups.groupId2).to.deep.equal(groups[1].groupSecondId); } else { - expect(groups[1].Users[0].usergroups.groupId2).to.equal(groups[1].groupSecondId); + expect(groups[1].users[0].usergroups.groupId2).to.equal(groups[1].groupSecondId); } - expect(groups[1].Users[0].usergroups.userId2).to.be.ok; + expect(groups[1].users[0].usergroups.userId2).to.be.ok; if (dialect === 'db2') { - expect(groups[1].Users[0].usergroups.userId2).to.deep.equal(groups[1].Users[0].userSecondId); + expect(groups[1].users[0].usergroups.userId2).to.deep.equal(groups[1].users[0].userSecondId); } else { - expect(groups[1].Users[0].usergroups.userId2).to.equal(groups[1].Users[0].userSecondId); + expect(groups[1].users[0].usergroups.userId2).to.equal(groups[1].users[0].userSecondId); } }); @@ -1109,65 +1112,65 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { })]); expect(users.length).to.equal(2); - expect(users[0].Groups.length).to.equal(1); - expect(users[1].Groups.length).to.equal(1); - expect(users[0].Groups[0].User_has_Group.userId2).to.be.ok; + expect(users[0].groups.length).to.equal(1); + expect(users[1].groups.length).to.equal(1); + expect(users[0].groups[0].User_has_Group.userId2).to.be.ok; if (dialect === 'db2') { - expect(users[0].Groups[0].User_has_Group.userId2).to.deep.equal(users[0].userSecondId); + expect(users[0].groups[0].User_has_Group.userId2).to.deep.equal(users[0].userSecondId); } else { - expect(users[0].Groups[0].User_has_Group.userId2).to.equal(users[0].userSecondId); + expect(users[0].groups[0].User_has_Group.userId2).to.equal(users[0].userSecondId); } - expect(users[0].Groups[0].User_has_Group.groupId2).to.be.ok; + expect(users[0].groups[0].User_has_Group.groupId2).to.be.ok; if (dialect === 'db2') { - expect(users[0].Groups[0].User_has_Group.groupId2).to.deep.equal(users[0].Groups[0].groupSecondId); + expect(users[0].groups[0].User_has_Group.groupId2).to.deep.equal(users[0].groups[0].groupSecondId); } else { - expect(users[0].Groups[0].User_has_Group.groupId2).to.equal(users[0].Groups[0].groupSecondId); + expect(users[0].groups[0].User_has_Group.groupId2).to.equal(users[0].groups[0].groupSecondId); } - expect(users[1].Groups[0].User_has_Group.userId2).to.be.ok; + expect(users[1].groups[0].User_has_Group.userId2).to.be.ok; if (dialect === 'db2') { - expect(users[1].Groups[0].User_has_Group.userId2).to.deep.equal(users[1].userSecondId); + expect(users[1].groups[0].User_has_Group.userId2).to.deep.equal(users[1].userSecondId); } else { - expect(users[1].Groups[0].User_has_Group.userId2).to.equal(users[1].userSecondId); + expect(users[1].groups[0].User_has_Group.userId2).to.equal(users[1].userSecondId); } - expect(users[1].Groups[0].User_has_Group.groupId2).to.be.ok; + expect(users[1].groups[0].User_has_Group.groupId2).to.be.ok; if (dialect === 'db2') { - expect(users[1].Groups[0].User_has_Group.groupId2).to.deep.equal(users[1].Groups[0].groupSecondId); + expect(users[1].groups[0].User_has_Group.groupId2).to.deep.equal(users[1].groups[0].groupSecondId); } else { - expect(users[1].Groups[0].User_has_Group.groupId2).to.equal(users[1].Groups[0].groupSecondId); + expect(users[1].groups[0].User_has_Group.groupId2).to.equal(users[1].groups[0].groupSecondId); } expect(groups.length).to.equal(2); - expect(groups[0].Users.length).to.equal(1); - expect(groups[1].Users.length).to.equal(1); - expect(groups[0].Users[0].User_has_Group.groupId2).to.be.ok; + expect(groups[0].users.length).to.equal(1); + expect(groups[1].users.length).to.equal(1); + expect(groups[0].users[0].User_has_Group.groupId2).to.be.ok; if (dialect === 'db2') { - expect(groups[0].Users[0].User_has_Group.groupId2).to.deep.equal(groups[0].groupSecondId); + expect(groups[0].users[0].User_has_Group.groupId2).to.deep.equal(groups[0].groupSecondId); } else { - expect(groups[0].Users[0].User_has_Group.groupId2).to.equal(groups[0].groupSecondId); + expect(groups[0].users[0].User_has_Group.groupId2).to.equal(groups[0].groupSecondId); } - expect(groups[0].Users[0].User_has_Group.userId2).to.be.ok; + expect(groups[0].users[0].User_has_Group.userId2).to.be.ok; if (dialect === 'db2') { - expect(groups[0].Users[0].User_has_Group.userId2).to.deep.equal(groups[0].Users[0].userSecondId); + expect(groups[0].users[0].User_has_Group.userId2).to.deep.equal(groups[0].users[0].userSecondId); } else { - expect(groups[0].Users[0].User_has_Group.userId2).to.equal(groups[0].Users[0].userSecondId); + expect(groups[0].users[0].User_has_Group.userId2).to.equal(groups[0].users[0].userSecondId); } - expect(groups[1].Users[0].User_has_Group.groupId2).to.be.ok; + expect(groups[1].users[0].User_has_Group.groupId2).to.be.ok; if (dialect === 'db2') { - expect(groups[1].Users[0].User_has_Group.groupId2).to.deep.equal(groups[1].groupSecondId); + expect(groups[1].users[0].User_has_Group.groupId2).to.deep.equal(groups[1].groupSecondId); } else { - expect(groups[1].Users[0].User_has_Group.groupId2).to.equal(groups[1].groupSecondId); + expect(groups[1].users[0].User_has_Group.groupId2).to.equal(groups[1].groupSecondId); } - expect(groups[1].Users[0].User_has_Group.userId2).to.be.ok; + expect(groups[1].users[0].User_has_Group.userId2).to.be.ok; if (dialect === 'db2') { - expect(groups[1].Users[0].User_has_Group.userId2).to.deep.equal(groups[1].Users[0].userSecondId); + expect(groups[1].users[0].User_has_Group.userId2).to.deep.equal(groups[1].users[0].userSecondId); } else { - expect(groups[1].Users[0].User_has_Group.userId2).to.equal(groups[1].Users[0].userSecondId); + expect(groups[1].users[0].User_has_Group.userId2).to.equal(groups[1].users[0].userSecondId); } }); @@ -2003,8 +2006,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { status: DataTypes.STRING, }); - User.belongsToMany(Task, { through: UserTask }); - Task.belongsToMany(User, { through: UserTask }); + User.belongsToMany(Task, { through: UserTask, as: 'Tasks', inverse: 'Users' }); await sequelize.sync({ force: true }); const [user, task, t] = await Promise.all([ @@ -2035,8 +2037,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { const User = this.sequelize.define('User', { username: DataTypes.STRING }); const Task = this.sequelize.define('Task', { title: DataTypes.STRING }); - User.belongsToMany(Task, { through: 'UserTasks' }); - Task.belongsToMany(User, { through: 'UserTasks' }); + User.belongsToMany(Task, { through: 'UserTasks', as: 'Tasks', inverse: 'Users' }); await this.sequelize.sync({ force: true }); @@ -2385,8 +2386,8 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { const attributes = this.sequelize.model('user_places').getAttributes(); - expect(attributes.PlaceId.field).to.equal('PlaceId'); - expect(attributes.UserId.field).to.equal('UserId'); + expect(attributes.placeId.field).to.equal('placeId'); + expect(attributes.userId.field).to.equal('userId'); }); it('generates snake_case foreign keys if underscored is set on the through model', function () { @@ -2399,8 +2400,8 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { const attributes = UserPlaces.getAttributes(); - expect(attributes.PlaceId.field).to.equal('place_id'); - expect(attributes.UserId.field).to.equal('user_id'); + expect(attributes.placeId.field).to.equal('place_id'); + expect(attributes.userId.field).to.equal('user_id'); }); it('should infer otherKey from paired BTM relationship with a through string defined', function () { @@ -2600,7 +2601,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { this.User.belongsToMany(this.Task, { through: this.UserTasks }); this.Task.belongsToMany(this.User, { through: this.UserTasks }); - expect(Object.keys(this.UserTasks.primaryKeys).sort()).to.deep.equal(['TaskId', 'UserId']); + expect(Object.keys(this.UserTasks.primaryKeys).sort()).to.deep.equal(['taskId', 'userId']); }); it('keeps the primary key if it was added by the user', function () { @@ -2628,7 +2629,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { for (const model of [this.UserTasks, this.UserTasks2]) { const index = model.getIndexes()[0]; - expect(index.fields.sort()).to.deep.equal(['TaskId', 'UserId']); + expect(index.fields.sort()).to.deep.equal(['taskId', 'userId']); } }); @@ -2656,8 +2657,8 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { }); return this.sequelize.queryInterface.createTable('users_tasks', { - TaskId: DataTypes.INTEGER, - UserId: DataTypes.INTEGER, + taskId: DataTypes.INTEGER, + userId: DataTypes.INTEGER, createdAt: DataTypes.DATE, updatedAt: DataTypes.DATE, }); @@ -2669,7 +2670,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { this.User.belongsToMany(this.Task, { through: this.UsersTasks }); this.Task.belongsToMany(this.User, { through: this.UsersTasks }); - expect(Object.keys(this.UsersTasks.primaryKeys).sort()).to.deep.equal(['TaskId', 'UserId']); + expect(Object.keys(this.UsersTasks.primaryKeys).sort()).to.deep.equal(['taskId', 'userId']); const [user, task] = await Promise.all([ this.User.create({ username: 'foo' }), @@ -2715,7 +2716,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { await this.users[0].addProjects(this.projects); await this.UserProjects.destroy({ where: { - ProjectId: this.projects[0].id, + projectId: this.projects[0].id, }, }); @@ -2728,7 +2729,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { await this.users[0].addProjects(this.projects); await this.UserProjects.destroy({ where: { - ProjectId: this.projects[0].id, + projectId: this.projects[0].id, }, }); @@ -2741,7 +2742,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { await this.users[0].addProjects(this.projects); await this.UserProjects.destroy({ where: { - ProjectId: this.projects[0].id, + projectId: this.projects[0].id, }, }); @@ -2788,10 +2789,10 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { const projects = await user.getProjects(); const project = projects[0]; - expect(project.UserProject).to.be.ok; + expect(project.userProject).to.be.ok; expect(project.status).not.to.exist; - expect(project.UserProject.status).to.equal('active'); - expect(project.UserProject.data).to.equal(42); + expect(project.userProject.status).to.equal('active'); + expect(project.userProject.data).to.equal(42); }); it('should be able to alias the default name of the join table', async function () { @@ -2811,7 +2812,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { }], }); - const project = users[0].Projects[0]; + const project = users[0].projects[0]; expect(project.UserProjects).not.to.exist; expect(project.status).not.to.exist; @@ -2830,10 +2831,10 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { const projects = await user.getProjects({ joinTableAttributes: ['status'] }); const project = projects[0]; - expect(project.UserProject).to.be.ok; + expect(project.userProject).to.be.ok; expect(project.status).not.to.exist; - expect(project.UserProject.status).to.equal('active'); - expect(project.UserProject.data).not.to.exist; + expect(project.userProject.status).to.equal('active'); + expect(project.userProject.data).not.to.exist; }); }); @@ -2862,7 +2863,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { p.UserProjects = { status: 'active' }; await u.addProject(p); - const up = await this.UserProjects.findOne({ where: { UserId: u.id, ProjectId: p.id } }); + const up = await this.UserProjects.findOne({ where: { userId: u.id, projectId: p.id } }); expect(up.status).to.equal('active'); }); @@ -2873,7 +2874,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ]); await u.addProject(p, { through: { status: 'active' } }); - const up = await this.UserProjects.findOne({ where: { UserId: u.id, ProjectId: p.id } }); + const up = await this.UserProjects.findOne({ where: { userId: u.id, projectId: p.id } }); expect(up.status).to.equal('active'); }); @@ -2983,8 +2984,8 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { await user.setProjects([p1, p2], { through: { status: 'active' } }); const [up1, up2] = await Promise.all([ - this.UserProjects.findOne({ where: { UserId: user.id, ProjectId: p1.id } }), - this.UserProjects.findOne({ where: { UserId: user.id, ProjectId: p2.id } }), + this.UserProjects.findOne({ where: { userId: user.id, projectId: p1.id } }), + this.UserProjects.findOne({ where: { userId: user.id, projectId: p2.id } }), ]); expect(up1.status).to.equal('inactive'); @@ -3093,63 +3094,6 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { }); }); - describe('alias', () => { - it('creates the join table when through is a string', async function () { - const User = this.sequelize.define('User', {}); - const Group = this.sequelize.define('Group', {}); - - User.belongsToMany(Group, { as: 'MyGroups', through: 'group_user' }); - Group.belongsToMany(User, { as: 'MyUsers', through: 'group_user' }); - - await this.sequelize.sync({ force: true }); - const result = await this.sequelize.queryInterface.listTables(); - const tableNames = result.map(v => v.tableName); - - expect(tableNames.includes('group_user')).to.be.true; - }); - - it('creates the join table when through is a model', async function () { - const User = this.sequelize.define('User', {}); - const Group = this.sequelize.define('Group', {}); - const UserGroup = this.sequelize.define('GroupUser', {}, { tableName: 'user_groups' }); - - User.belongsToMany(Group, { as: 'MyGroups', through: UserGroup }); - Group.belongsToMany(User, { as: 'MyUsers', through: UserGroup }); - - await this.sequelize.sync({ force: true }); - const result = await this.sequelize.queryInterface.listTables(); - const tableNames = result.map(v => v.tableName); - - expect(tableNames).to.include('user_groups'); - }); - - it('correctly identifies its counterpart when through is a string', function () { - const User = this.sequelize.define('User', {}); - const Group = this.sequelize.define('Group', {}); - - User.belongsToMany(Group, { as: 'MyGroups', through: 'group_user' }); - Group.belongsToMany(User, { as: 'MyUsers', through: 'group_user' }); - - expect(Group.associations.MyUsers.through.model === User.associations.MyGroups.through.model); - expect(Group.associations.MyUsers.through.model.getAttributes().UserId).to.exist; - expect(Group.associations.MyUsers.through.model.getAttributes().GroupId).to.exist; - }); - - it('correctly identifies its counterpart when through is a model', function () { - const User = this.sequelize.define('User', {}); - const Group = this.sequelize.define('Group', {}); - const UserGroup = this.sequelize.define('GroupUser', {}, { tableName: 'user_groups' }); - - User.belongsToMany(Group, { as: 'MyGroups', through: UserGroup }); - Group.belongsToMany(User, { as: 'MyUsers', through: UserGroup }); - - expect(Group.associations.MyUsers.through.model === User.associations.MyGroups.through.model); - - expect(Group.associations.MyUsers.through.model.getAttributes().UserId).to.exist; - expect(Group.associations.MyUsers.through.model.getAttributes().GroupId).to.exist; - }); - }); - describe('multiple hasMany', () => { beforeEach(function () { this.User = this.sequelize.define('user', { name: DataTypes.STRING }); @@ -3412,7 +3356,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { singular: 'Invitee', plural: 'Invitees', }, - foreignKey: 'InviteeId', + foreignKey: 'inviteeId', through: 'Invites', inverse: { as: 'Hosts', diff --git a/packages/core/test/integration/associations/belongs-to.test.js b/packages/core/test/integration/associations/belongs-to.test.js index d0ec717c4317..e78f0362eaa6 100644 --- a/packages/core/test/integration/associations/belongs-to.test.js +++ b/packages/core/test/integration/associations/belongs-to.test.js @@ -23,7 +23,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { expect( Object.keys(Group.associations), - ).to.deep.equal(['User', 'primaryUsers', 'secondaryUsers']); + ).to.deep.equal(['user', 'primaryUsers', 'secondaryUsers']); }); }); @@ -228,10 +228,10 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { Task.belongsTo(User); await this.sequelize.sync({ force: true }); - await expect(Task.create({ title: 'task', UserXYZId: 5 })).to.be.rejectedWith(Sequelize.ForeignKeyConstraintError); + await expect(Task.create({ title: 'task', userXYZId: 5 })).to.be.rejectedWith(Sequelize.ForeignKeyConstraintError); const task = await Task.create({ title: 'task' }); - await expect(Task.update({ title: 'taskUpdate', UserXYZId: 5 }, { where: { id: task.id } })).to.be.rejectedWith(Sequelize.ForeignKeyConstraintError); + await expect(Task.update({ title: 'taskUpdate', userXYZId: 5 }, { where: { id: task.id } })).to.be.rejectedWith(Sequelize.ForeignKeyConstraintError); }); it('supports passing the primary key instead of an object', async function () { @@ -372,8 +372,8 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { User.belongsTo(Account); - expect(User.getAttributes().AccountId).to.exist; - expect(User.getAttributes().AccountId.field).to.equal('account_id'); + expect(User.getAttributes().accountId).to.exist; + expect(User.getAttributes().accountId.field).to.equal('account_id'); }); it('should use model name when using camelcase', function () { @@ -382,8 +382,8 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { User.belongsTo(Account); - expect(User.getAttributes().AccountId).to.exist; - expect(User.getAttributes().AccountId.field).to.equal('AccountId'); + expect(User.getAttributes().accountId).to.exist; + expect(User.getAttributes().accountId.field).to.equal('accountId'); }); it('should support specifying the field of a foreign key', async function () { @@ -419,7 +419,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { }); // the sql query should correctly look at account_id instead of AccountId - expect(user.Account).to.exist; + expect(user.account).to.exist; }); it('should set foreignKey on foreign table', async function () { @@ -537,7 +537,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { await task.setUser(user); await user.destroy(); await task.reload(); - expect(task.UserId).to.equal(null); + expect(task.userId).to.equal(null); }); it('should be possible to disable them', async function () { @@ -552,7 +552,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { await task.setUser(user); await user.destroy(); await task.reload(); - expect(task.UserId).to.equal(user.id); + expect(task.userId).to.equal(user.id); }); it('can cascade deletes', async function () { @@ -635,7 +635,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { await user.sequelize.queryInterface.update(user, tableName, { id: 999 }, { id: user.id }); const tasks = await Task.findAll(); expect(tasks).to.have.length(1); - expect(tasks[0].UserId).to.equal(999); + expect(tasks[0].userId).to.equal(999); }); } }); @@ -658,7 +658,7 @@ describe(Support.getTestDialectTeaser('BelongsTo'), () => { User.belongsTo(Group); await this.sequelize.sync({ force: true }); - expect(User.getAttributes().GroupPKBTName.type).to.an.instanceof(DataTypes.STRING); + expect(User.getAttributes().groupPKBTName.type).to.an.instanceof(DataTypes.STRING); }); it('should support a non-primary key as the association column on a target without a primary key', async function () { diff --git a/packages/core/test/integration/associations/has-many.test.js b/packages/core/test/integration/associations/has-many.test.js index 77a2cffd720a..6d90e07e5baf 100644 --- a/packages/core/test/integration/associations/has-many.test.js +++ b/packages/core/test/integration/associations/has-many.test.js @@ -25,7 +25,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { Group.hasMany(User, { foreignKey: 'primaryGroupId', as: 'primaryUsers', inverse: { as: 'primaryGroup' } }); Group.hasMany(User, { foreignKey: 'secondaryGroupId', as: 'secondaryUsers', inverse: { as: 'secondaryGroup' } }); - expect(Object.keys(Group.associations)).to.deep.equal(['Users', 'primaryUsers', 'secondaryUsers']); + expect(Object.keys(Group.associations)).to.deep.equal(['users', 'primaryUsers', 'secondaryUsers']); }); }); @@ -41,7 +41,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { const user0 = await User.create({ username: 'John', - Tasks: [{ + tasks: [{ title: 'Get rich', active: true, }], }, { @@ -49,8 +49,8 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { }); await Promise.all([ - user0.get('Tasks')[0].createSubtask({ title: 'Make a startup', active: false }), - user0.get('Tasks')[0].createSubtask({ title: 'Engage rock stars', active: true }), + user0.get('tasks')[0].createSubtask({ title: 'Make a startup', active: false }), + user0.get('tasks')[0].createSubtask({ title: 'Engage rock stars', active: true }), ]); const user = user0; @@ -497,8 +497,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { this.Label.belongsTo(this.Article); this.Article.hasMany(this.Label); - expect(Object.keys(this.Label.getAttributes())).to.deep.equal(['id', 'text', 'ArticleId']); - expect(Object.keys(this.Label.getAttributes()).length).to.equal(3); + expect(Object.keys(this.Label.getAttributes())).to.deep.equal(['id', 'text', 'articleId']); }); if (current.dialect.supports.transactions) { @@ -713,10 +712,10 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { const t = await sequelize.startUnmanagedTransaction(); await article.addLabel(label, { transaction: t }); - const labels0 = await Label.findAll({ where: { ArticleId: article.id }, transaction: undefined }); + const labels0 = await Label.findAll({ where: { articleId: article.id }, transaction: undefined }); expect(labels0.length).to.equal(0); - const labels = await Label.findAll({ where: { ArticleId: article.id }, transaction: t }); + const labels = await Label.findAll({ where: { articleId: article.id }, transaction: t }); expect(labels.length).to.equal(1); await t.rollback(); }); @@ -811,7 +810,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { const article0 = await Article.create({ title: 'foo' }); await article0.createLabel({ text: 'bar' }); const article = article0; - const labels = await Label.findAll({ where: { ArticleId: article.id } }); + const labels = await Label.findAll({ where: { articleId: article.id } }); expect(labels.length).to.equal(1); }); @@ -832,7 +831,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { const article = await Article.create({ title: 'foo' }); const label = await article.createLabel({ text: 'bar' }, { logging: spy }); expect(spy.calledOnce).to.be.true; - expect(label.ArticleId).to.equal(article.id); + expect(label.articleId).to.equal(article.id); }); if (current.dialect.supports.transactions) { @@ -849,9 +848,9 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { await article.createLabel({ text: 'bar' }, { transaction: t }); const labels1 = await Label.findAll(); expect(labels1.length).to.equal(0); - const labels0 = await Label.findAll({ where: { ArticleId: article.id } }); + const labels0 = await Label.findAll({ where: { articleId: article.id } }); expect(labels0.length).to.equal(0); - const labels = await Label.findAll({ where: { ArticleId: article.id }, transaction: t }); + const labels = await Label.findAll({ where: { articleId: article.id }, transaction: t }); expect(labels.length).to.equal(1); await t.rollback(); }); @@ -1018,7 +1017,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { await user.setTasks([task0]); await user.destroy(); const task = await task0.reload(); - expect(task.UserId).to.equal(null); + expect(task.userId).to.equal(null); }); it('sets to CASCADE if allowNull: false', async function () { @@ -1030,7 +1029,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { await this.sequelize.sync({ force: true }); const user = await User.create({ username: 'foo' }); - await Task.create({ title: 'task', UserId: user.id }); + await Task.create({ title: 'task', userId: user.id }); await user.destroy(); const tasks = await Task.findAll(); expect(tasks).to.be.empty; @@ -1053,7 +1052,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { await user.setTasks([task0]); await user.destroy(); await task.reload(); - expect(task.UserId).to.equal(user.id); + expect(task.userId).to.equal(user.id); }); it('can cascade deletes', async function () { @@ -1100,7 +1099,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { await user.sequelize.queryInterface.update(user, tableName, { id: 999 }, { id: user.id }); const tasks = await Task.findAll(); expect(tasks).to.have.length(1); - expect(tasks[0].UserId).to.equal(999); + expect(tasks[0].userId).to.equal(999); }); } @@ -1181,8 +1180,8 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { User.hasMany(Account); - expect(Account.getAttributes().UserId).to.exist; - expect(Account.getAttributes().UserId.field).to.equal('user_id'); + expect(Account.getAttributes().userId).to.exist; + expect(Account.getAttributes().userId.field).to.equal('user_id'); }); it('should use model name when using camelcase', function () { @@ -1191,8 +1190,8 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { User.hasMany(Account); - expect(Account.getAttributes().UserId).to.exist; - expect(Account.getAttributes().UserId.field).to.equal('UserId'); + expect(Account.getAttributes().userId).to.exist; + expect(Account.getAttributes().userId.field).to.equal('userId'); }); it('can specify data type for auto-generated relational keys', async function () { @@ -1223,7 +1222,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { User.hasMany(Task); await this.sequelize.sync({ force: true }); - expect(Task.getAttributes().UserId.type instanceof DataTypes.STRING).to.be.ok; + expect(Task.getAttributes().userId.type instanceof DataTypes.STRING).to.be.ok; }); describe('allows the user to provide an attribute definition object as foreignKey', () => { @@ -1448,7 +1447,9 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { }, }, }); + Child.belongsTo(Parent, { + as: 'Parent', foreignKey: 'parent', targetKey: 'id', inverse: { @@ -1511,8 +1512,8 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { }); expect(user).to.be.ok; - expect(user.Tasks.length).to.equal(1); - expect(user.Tasks[0].title).to.equal('Active Task'); + expect(user.tasks.length).to.equal(1); + expect(user.tasks[0].title).to.equal('Active Task'); }); }); diff --git a/packages/core/test/integration/associations/has-one.test.js b/packages/core/test/integration/associations/has-one.test.js index 2d78fd10bf40..3bb8bb377eb5 100644 --- a/packages/core/test/integration/associations/has-one.test.js +++ b/packages/core/test/integration/associations/has-one.test.js @@ -167,10 +167,10 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { await User.sync({ force: true }); await Task.sync({ force: true }); - await expect(Task.create({ title: 'task', UserXYZId: 5 })).to.be.rejectedWith(Sequelize.ForeignKeyConstraintError); + await expect(Task.create({ title: 'task', userXYZId: 5 })).to.be.rejectedWith(Sequelize.ForeignKeyConstraintError); const task = await Task.create({ title: 'task' }); - await expect(Task.update({ title: 'taskUpdate', UserXYZId: 5 }, { where: { id: task.id } })).to.be.rejectedWith(Sequelize.ForeignKeyConstraintError); + await expect(Task.update({ title: 'taskUpdate', userXYZId: 5 }, { where: { id: task.id } })).to.be.rejectedWith(Sequelize.ForeignKeyConstraintError); }); it('should setup underscored field with foreign keys when using underscored', function () { @@ -179,8 +179,8 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { Account.hasOne(User); - expect(User.getAttributes().AccountId).to.exist; - expect(User.getAttributes().AccountId.field).to.equal('account_id'); + expect(User.getAttributes().accountId).to.exist; + expect(User.getAttributes().accountId.field).to.equal('account_id'); }); it('should use model name when using camelcase', function () { @@ -189,8 +189,8 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { Account.hasOne(User); - expect(User.getAttributes().AccountId).to.exist; - expect(User.getAttributes().AccountId.field).to.equal('AccountId'); + expect(User.getAttributes().accountId).to.exist; + expect(User.getAttributes().accountId.field).to.equal('accountId'); }); it('should support specifying the field of a foreign key', async function () { @@ -224,7 +224,7 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { include: [User], }); - expect(task.UserXYZ).to.exist; + expect(task.userXYZ).to.exist; }); it('should support custom primary key field name in sub queries', async function () { @@ -263,7 +263,7 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { await user.setTask(task); await user.destroy(); await task.reload(); - expect(task.UserId).to.equal(null); + expect(task.userId).to.equal(null); }); it('should be possible to disable them', async function () { @@ -279,7 +279,7 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { await user.setTask(task); await user.destroy(); await task.reload(); - expect(task.UserId).to.equal(user.id); + expect(task.userId).to.equal(user.id); }); it('can cascade deletes', async function () { @@ -333,7 +333,7 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { await user.sequelize.queryInterface.update(user, tableName, { id: 999 }, { id: user.id }); const tasks = await Task.findAll(); expect(tasks).to.have.length(1); - expect(tasks[0].UserId).to.equal(999); + expect(tasks[0].userId).to.equal(999); }); } @@ -405,7 +405,7 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { Group.hasOne(User); await this.sequelize.sync({ force: true }); - expect(User.getAttributes().GroupPKBTName.type).to.an.instanceof(DataTypes.STRING); + expect(User.getAttributes().groupPKBTName.type).to.an.instanceof(DataTypes.STRING); }); it('should support a non-primary key as the association column on a target with custom primary key', async function () { @@ -517,8 +517,8 @@ describe(Support.getTestDialectTeaser('HasOne'), () => { // The model is named incorrectly. // The modal name should always be singular, so here sequelize assumes that "Orders" is singular - expect(InternetOrders.getAttributes().OrdersId).to.be.ok; - expect(InternetOrders.getAttributes().OrderId).not.to.be.ok; + expect(InternetOrders.getAttributes().ordersId).to.be.ok; + expect(InternetOrders.getAttributes().orderId).not.to.be.ok; }); }); }); diff --git a/packages/core/test/integration/associations/multiple-level-filters.test.js b/packages/core/test/integration/associations/multiple-level-filters.test.js index 81661b9ae818..d46d6736e7bf 100644 --- a/packages/core/test/integration/associations/multiple-level-filters.test.js +++ b/packages/core/test/integration/associations/multiple-level-filters.test.js @@ -27,24 +27,24 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => { }]); await Project.bulkCreate([{ - UserId: 1, + userId: 1, title: 'republic', }, { - UserId: 2, + userId: 2, title: 'empire', }]); await Task.bulkCreate([{ - ProjectId: 1, + projectId: 1, title: 'fight empire', }, { - ProjectId: 1, + projectId: 1, title: 'stablish republic', }, { - ProjectId: 2, + projectId: 2, title: 'destroy rebel alliance', }, { - ProjectId: 2, + projectId: 2, title: 'rule everything', }]); @@ -85,24 +85,24 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => { }]); await Project.bulkCreate([{ - UserId: 1, + userId: 1, title: 'republic', }, { - UserId: 2, + userId: 2, title: 'empire', }]); await Task.bulkCreate([{ - ProjectId: 1, + projectId: 1, title: 'fight empire', }, { - ProjectId: 1, + projectId: 1, title: 'stablish republic', }, { - ProjectId: 2, + projectId: 2, title: 'destroy rebel alliance', }, { - ProjectId: 2, + projectId: 2, title: 'rule everything', }]); @@ -148,24 +148,24 @@ describe(Support.getTestDialectTeaser('Multiple Level Filters'), () => { }]); await Project.bulkCreate([{ - UserId: 1, + userId: 1, title: 'republic', }, { - UserId: 2, + userId: 2, title: 'empire', }]); await Task.bulkCreate([{ - ProjectId: 1, + projectId: 1, title: 'fight empire', }, { - ProjectId: 1, + projectId: 1, title: 'stablish republic', }, { - ProjectId: 2, + projectId: 2, title: 'destroy rebel alliance', }, { - ProjectId: 2, + projectId: 2, title: 'rule everything', }]); diff --git a/packages/core/test/integration/data-types/methods.test.ts b/packages/core/test/integration/data-types/methods.test.ts index f5d71c50cece..aedf13d2c5cc 100644 --- a/packages/core/test/integration/data-types/methods.test.ts +++ b/packages/core/test/integration/data-types/methods.test.ts @@ -69,6 +69,7 @@ describe('DataType Methods', () => { Project.belongsToMany(User, { as: 'stakeholders', + inverse: 'stakeholdings', through: ProjectStakeholder, }); diff --git a/packages/core/test/integration/dialects/mssql/regressions.test.js b/packages/core/test/integration/dialects/mssql/regressions.test.js index 1214825469e2..1d4ddc8e2e36 100644 --- a/packages/core/test/integration/dialects/mssql/regressions.test.js +++ b/packages/core/test/integration/dialects/mssql/regressions.test.js @@ -80,8 +80,8 @@ if (dialect.startsWith('mssql')) { }); expect(logs).to.have.length(2); - expect(logs[0].User.get('UserName')).to.equal('Shaktimaan'); - expect(logs[1].User.get('UserName')).to.equal('Aryamaan'); + expect(logs[0].user.get('UserName')).to.equal('Shaktimaan'); + expect(logs[1].user.get('UserName')).to.equal('Aryamaan'); // #11258 and similar const otherLogs = await LoginLog.findAll({ @@ -101,8 +101,8 @@ if (dialect.startsWith('mssql')) { }); expect(otherLogs).to.have.length(2); - expect(otherLogs[0].User.get('UserName')).to.equal('Aryamaan'); - expect(otherLogs[1].User.get('UserName')).to.equal('Shaktimaan'); + expect(otherLogs[0].user.get('UserName')).to.equal('Aryamaan'); + expect(otherLogs[1].user.get('UserName')).to.equal('Shaktimaan'); // Separate queries can apply order freely const separateUsers = await User.findAll({ @@ -127,9 +127,9 @@ if (dialect.startsWith('mssql')) { expect(separateUsers).to.have.length(2); expect(separateUsers[0].get('UserName')).to.equal('Aryamaan'); - expect(separateUsers[0].get('LoginLogs')).to.have.length(1); + expect(separateUsers[0].get('loginLogs')).to.have.length(1); expect(separateUsers[1].get('UserName')).to.equal('Shaktimaan'); - expect(separateUsers[1].get('LoginLogs')).to.have.length(1); + expect(separateUsers[1].get('loginLogs')).to.have.length(1); }); it('allow referencing FK to different tables in a schema with onDelete, #10125', async function () { diff --git a/packages/core/test/integration/dialects/postgres/dao.test.js b/packages/core/test/integration/dialects/postgres/dao.test.js index 7bc990939a3a..46e0c68ae563 100644 --- a/packages/core/test/integration/dialects/postgres/dao.test.js +++ b/packages/core/test/integration/dialects/postgres/dao.test.js @@ -985,17 +985,17 @@ describe('[POSTGRES Specific] DAO', () => { { id: 1, name: 'Transfiguration', - ProfessorId: 1, + professorId: 1, }, { id: 2, name: 'Potions', - ProfessorId: 2, + professorId: 2, }, { id: 3, name: 'Defence Against the Dark Arts', - ProfessorId: 2, + professorId: 2, }, ]); @@ -1057,8 +1057,8 @@ describe('[POSTGRES Specific] DAO', () => { expect(professors.length).to.eql(2); expect(professors[0].fullName).to.eql('Albus Dumbledore'); - expect(professors[0].Classes.length).to.eql(1); - expect(professors[0].Classes[0].Students.length).to.eql(3); + expect(professors[0].classes.length).to.eql(1); + expect(professors[0].classes[0].students.length).to.eql(3); } finally { this.sequelize.queryGenerator.options.quoteIdentifiers = true; } diff --git a/packages/core/test/integration/include.test.js b/packages/core/test/integration/include.test.js index 2a87af00f948..c3009e158ed5 100644 --- a/packages/core/test/integration/include.test.js +++ b/packages/core/test/integration/include.test.js @@ -12,9 +12,9 @@ const dialect = Support.getTestDialect(); const current = Support.sequelize; const promiseProps = require('p-props'); -const sortById = function (a, b) { +function sortById(a, b) { return a.id < b.id ? -1 : 1; -}; +} describe(Support.getTestDialectTeaser('Include'), () => { describe('find', () => { @@ -135,7 +135,7 @@ Instead of specifying a Model, either: const result = await Table1.findAll({ raw: true, attributes: [ - [Sequelize.fn('SUM', Sequelize.col('Table2.Tables3.value')), 'sum'], + [Sequelize.fn('SUM', Sequelize.col('table2.Tables3.value')), 'sum'], ], include: [ { @@ -321,15 +321,16 @@ Instead of specifying a Model, either: }, include: [ { - model: User, include: [ + model: User, + include: [ { model: Group }, ], }, ], }); - expect(task.User).to.be.ok; - expect(task.User.Group).to.be.ok; + expect(task.user).to.be.ok; + expect(task.user.group).to.be.ok; }); it('should support a simple sibling set of belongsTo include', async function () { @@ -343,8 +344,8 @@ Instead of specifying a Model, either: await this.sequelize.sync({ force: true }); const task0 = await Task.create({ - User: {}, - Group: {}, + user: {}, + group: {}, }, { include: [User, Group], }); @@ -359,8 +360,8 @@ Instead of specifying a Model, either: ], }); - expect(task.User).to.be.ok; - expect(task.Group).to.be.ok; + expect(task.user).to.be.ok; + expect(task.group).to.be.ok; }); it('should support a simple nested hasOne -> hasOne include', async function () { @@ -375,27 +376,28 @@ Instead of specifying a Model, either: await this.sequelize.sync({ force: true }); const user = await User.create({ - Task: {}, - Group: {}, + task: {}, + group: {}, }, { include: [Task, Group], }); const group = await Group.findOne({ where: { - id: user.Group.id, + id: user.group.id, }, include: [ { - model: User, include: [ + model: User, + include: [ { model: Task }, ], }, ], }); - expect(group.User).to.be.ok; - expect(group.User.Task).to.be.ok; + expect(group.user).to.be.ok; + expect(group.user.task).to.be.ok; }); it('should support a simple nested hasMany -> belongsTo include', async function () { @@ -410,11 +412,11 @@ Instead of specifying a Model, either: await Project.bulkCreate([{ id: 1 }, { id: 2 }]); const user0 = await User.create({ - Tasks: [ - { ProjectId: 1 }, - { ProjectId: 2 }, - { ProjectId: 1 }, - { ProjectId: 2 }, + tasks: [ + { projectId: 1 }, + { projectId: 2 }, + { projectId: 1 }, + { projectId: 2 }, ], }, { include: [Task], @@ -426,18 +428,19 @@ Instead of specifying a Model, either: }, include: [ { - model: Task, include: [ + model: Task, + include: [ { model: Project }, ], }, ], }); - expect(user.Tasks).to.be.ok; - expect(user.Tasks.length).to.equal(4); + expect(user.tasks).to.be.ok; + expect(user.tasks.length).to.equal(4); - for (const task of user.Tasks) { - expect(task.Project).to.be.ok; + for (const task of user.tasks) { + expect(task.project).to.be.ok; } }); @@ -453,28 +456,29 @@ Instead of specifying a Model, either: await this.sequelize.sync({ force: true }); const project = await Project.create({ - Workers: [{}], - Tasks: [{}, {}, {}, {}], + workers: [{}], + tasks: [{}, {}, {}, {}], }, { include: [Worker, Task], }); const worker = await Worker.findOne({ where: { - id: project.Workers[0].id, + id: project.workers[0].id, }, include: [ { - model: Project, include: [ + model: Project, + include: [ { model: Task }, ], }, ], }); - expect(worker.Project).to.be.ok; - expect(worker.Project.Tasks).to.be.ok; - expect(worker.Project.Tasks.length).to.equal(4); + expect(worker.project).to.be.ok; + expect(worker.project.tasks).to.be.ok; + expect(worker.project.tasks.length).to.equal(4); }); it('should support a simple nested hasMany to hasMany include', async function () { @@ -495,7 +499,7 @@ Instead of specifying a Model, either: const [products, tags] = await Promise.all([ User.create({ id: 1, - Products: [ + products: [ { title: 'Chair' }, { title: 'Desk' }, { title: 'Dress' }, @@ -539,11 +543,11 @@ Instead of specifying a Model, either: ], }); - expect(user.Products.length).to.equal(4); - expect(user.Products[0].Tags.length).to.equal(2); - expect(user.Products[1].Tags.length).to.equal(1); - expect(user.Products[2].Tags.length).to.equal(3); - expect(user.Products[3].Tags.length).to.equal(0); + expect(user.products.length).to.equal(4); + expect(user.products[0].tags.length).to.equal(2); + expect(user.products[1].tags.length).to.equal(1); + expect(user.products[2].tags.length).to.equal(3); + expect(user.products[3].tags.length).to.equal(0); }); it('should support an include with multiple different association types', async function () { @@ -595,18 +599,18 @@ Instead of specifying a Model, either: Product.create({ id: 1, title: 'Chair', - Prices: [{ value: 5 }, { value: 10 }], + prices: [{ value: 5 }, { value: 10 }], }, { include: [Price] }), Product.create({ id: 2, title: 'Desk', - Prices: [{ value: 5 }, { value: 10 }, { value: 15 }, { value: 20 }], + prices: [{ value: 5 }, { value: 10 }, { value: 15 }, { value: 20 }], }, { include: [Price] }), User.create({ id: 1, Memberships: [ - { id: 1, Group: { name: 'Developers' }, Rank: { name: 'Admin', canInvite: 1, canRemove: 1 } }, - { id: 2, Group: { name: 'Designers' }, Rank: { name: 'Member', canInvite: 1, canRemove: 0 } }, + { id: 1, group: { name: 'Developers' }, rank: { name: 'Admin', canInvite: 1, canRemove: 1 } }, + { id: 2, group: { name: 'Designers' }, rank: { name: 'Member', canInvite: 1, canRemove: 0 } }, ], }, { include: { model: GroupMember, as: 'Memberships', include: [Group, Rank] }, @@ -638,7 +642,7 @@ Instead of specifying a Model, either: }, { model: Product, include: [ - { model: Tag, as: 'Tags' }, + { model: Tag, as: 'tags' }, { model: Tag, as: 'Category' }, Price, ], @@ -648,20 +652,20 @@ Instead of specifying a Model, either: user.Memberships.sort(sortById); expect(user.Memberships.length).to.equal(2); - expect(user.Memberships[0].Group.name).to.equal('Developers'); - expect(user.Memberships[0].Rank.canRemove).to.equal(1); - expect(user.Memberships[1].Group.name).to.equal('Designers'); - expect(user.Memberships[1].Rank.canRemove).to.equal(0); - - user.Products.sort(sortById); - expect(user.Products.length).to.equal(2); - expect(user.Products[0].Tags.length).to.equal(2); - expect(user.Products[1].Tags.length).to.equal(1); - expect(user.Products[0].Category).to.be.ok; - expect(user.Products[1].Category).not.to.be.ok; - - expect(user.Products[0].Prices.length).to.equal(2); - expect(user.Products[1].Prices.length).to.equal(4); + expect(user.Memberships[0].group.name).to.equal('Developers'); + expect(user.Memberships[0].rank.canRemove).to.equal(1); + expect(user.Memberships[1].group.name).to.equal('Designers'); + expect(user.Memberships[1].rank.canRemove).to.equal(0); + + user.products.sort(sortById); + expect(user.products.length).to.equal(2); + expect(user.products[0].tags.length).to.equal(2); + expect(user.products[1].tags.length).to.equal(1); + expect(user.products[0].Category).to.be.ok; + expect(user.products[1].Category).not.to.be.ok; + + expect(user.products[0].prices.length).to.equal(2); + expect(user.products[1].prices.length).to.equal(4); }); it('should support specifying attributes', async function () { @@ -681,7 +685,7 @@ Instead of specifying a Model, either: await Task.create({ title: 'FooBar', - Project: { title: 'BarFoo' }, + project: { title: 'BarFoo' }, }, { include: [Project], }); @@ -694,10 +698,10 @@ Instead of specifying a Model, either: }); expect(tasks[0].title).to.equal('FooBar'); - expect(tasks[0].Project.title).to.equal('BarFoo'); + expect(tasks[0].project.title).to.equal('BarFoo'); - expect(omit(tasks[0].get(), 'Project')).to.deep.equal({ title: 'FooBar' }); - expect(tasks[0].Project.get()).to.deep.equal({ title: 'BarFoo' }); + expect(omit(tasks[0].get(), 'project')).to.deep.equal({ title: 'FooBar' }); + expect(tasks[0].project.get()).to.deep.equal({ title: 'BarFoo' }); }); it('should support Sequelize.literal and renaming of attributes in included model attributes', async function () { @@ -720,7 +724,7 @@ Instead of specifying a Model, either: switch (dialect) { case 'mssql': { findAttributes = [ - Sequelize.literal('CAST(CASE WHEN EXISTS(SELECT 1) THEN 1 ELSE 0 END AS BIT) AS "PostComments.someProperty"'), + Sequelize.literal('CAST(CASE WHEN EXISTS(SELECT 1) THEN 1 ELSE 0 END AS BIT) AS "postComments.someProperty"'), [Sequelize.literal('CAST(CASE WHEN EXISTS(SELECT 1) THEN 1 ELSE 0 END AS BIT)'), 'someProperty2'], ]; @@ -729,7 +733,7 @@ Instead of specifying a Model, either: case 'ibmi': { findAttributes = [ - Sequelize.literal('1 AS "PostComments.someProperty"'), + Sequelize.literal('1 AS "postComments.someProperty"'), [Sequelize.literal('1'), 'someProperty2'], ]; @@ -738,7 +742,7 @@ Instead of specifying a Model, either: case 'db2': { findAttributes = [ - Sequelize.literal('EXISTS(SELECT 1 FROM SYSIBM.SYSDUMMY1) AS "PostComments.someProperty"'), + Sequelize.literal('EXISTS(SELECT 1 FROM SYSIBM.SYSDUMMY1) AS "postComments.someProperty"'), [Sequelize.literal('EXISTS(SELECT 1 FROM SYSIBM.SYSDUMMY1)'), 'someProperty2'], ]; @@ -747,7 +751,7 @@ Instead of specifying a Model, either: default: { findAttributes = [ - Sequelize.literal('EXISTS(SELECT 1) AS "PostComments.someProperty"'), + Sequelize.literal('EXISTS(SELECT 1) AS "postComments.someProperty"'), [Sequelize.literal('EXISTS(SELECT 1)'), 'someProperty2'], ]; } @@ -764,9 +768,9 @@ Instead of specifying a Model, either: ], }); - expect(posts[0].PostComments[0].get('someProperty')).to.be.ok; - expect(posts[0].PostComments[0].get('someProperty2')).to.be.ok; - expect(posts[0].PostComments[0].get('commentTitle')).to.equal('WAT'); + expect(posts[0].postComments[0].get('someProperty')).to.be.ok; + expect(posts[0].postComments[0].get('someProperty2')).to.be.ok; + expect(posts[0].postComments[0].get('commentTitle')).to.equal('WAT'); }); it('should support self associated hasMany (with through) include', async function () { @@ -918,7 +922,7 @@ Instead of specifying a Model, either: }); expect(result.length).to.eql(1); - expect(result[0].Item.test).to.eql('def'); + expect(result[0].item.test).to.eql('def'); }); it('should support or()', async function () { @@ -955,7 +959,7 @@ Instead of specifying a Model, either: expect(result.count).to.eql(1); expect(result.rows.length).to.eql(1); - expect(result.rows[0].Item.test).to.eql('def'); + expect(result.rows[0].item.test).to.eql('def'); }); }); diff --git a/packages/core/test/integration/include/findAll.test.js b/packages/core/test/integration/include/findAll.test.js index f4a5072c86e8..9ccd98043837 100644 --- a/packages/core/test/integration/include/findAll.test.js +++ b/packages/core/test/integration/include/findAll.test.js @@ -10,9 +10,9 @@ const Support = require('../support'); const { DataTypes, Op } = require('@sequelize/core'); const promiseProps = require('p-props'); -const sortById = function (a, b) { +function sortById(a, b) { return a.id < b.id ? -1 : 1; -}; +} describe(Support.getTestDialectTeaser('Include'), () => { describe('findAll', () => { @@ -123,11 +123,11 @@ describe(Support.getTestDialectTeaser('Include'), () => { ]); const products = await Product.findAll(); const groupMembers = [ - { AccUserId: user.id, GroupId: groups[0].id, RankId: ranks[0].id }, - { AccUserId: user.id, GroupId: groups[1].id, RankId: ranks[2].id }, + { groupId: groups[0].id, rankId: ranks[0].id }, + { groupId: groups[1].id, rankId: ranks[2].id }, ]; if (i < 3) { - groupMembers.push({ AccUserId: user.id, GroupId: groups[2].id, RankId: ranks[1].id }); + groupMembers.push({ groupId: groups[2].id, rankId: ranks[1].id }); } await Promise.all([ @@ -157,14 +157,14 @@ describe(Support.getTestDialectTeaser('Include'), () => { products[i * 5 + 3].setCompany(companies[1]), products[i * 5 + 4].setCompany(companies[0]), Price.bulkCreate([ - { ProductId: products[i * 5 + 0].id, value: 5 }, - { ProductId: products[i * 5 + 0].id, value: 10 }, - { ProductId: products[i * 5 + 1].id, value: 5 }, - { ProductId: products[i * 5 + 1].id, value: 10 }, - { ProductId: products[i * 5 + 1].id, value: 15 }, - { ProductId: products[i * 5 + 1].id, value: 20 }, - { ProductId: products[i * 5 + 2].id, value: 20 }, - { ProductId: products[i * 5 + 3].id, value: 20 }, + { productId: products[i * 5 + 0].id, value: 5 }, + { productId: products[i * 5 + 0].id, value: 10 }, + { productId: products[i * 5 + 1].id, value: 5 }, + { productId: products[i * 5 + 1].id, value: 10 }, + { productId: products[i * 5 + 1].id, value: 15 }, + { productId: products[i * 5 + 1].id, value: 20 }, + { productId: products[i * 5 + 2].id, value: 20 }, + { productId: products[i * 5 + 3].id, value: 20 }, ]), ]); } @@ -243,39 +243,46 @@ describe(Support.getTestDialectTeaser('Include'), () => { title: DataTypes.STRING, }); - Set.hasMany(Product); - Product.belongsTo(Set); + Set.hasMany(Product, { inverse: 'Set', as: 'Products' }); Product.belongsToMany(Tag, { through: ProductTag }); Tag.belongsToMany(Product, { through: ProductTag }); await this.sequelize.sync({ force: true }); - await Promise.all([Set.bulkCreate([ - { title: 'office' }, - ]), Product.bulkCreate([ - { title: 'Chair' }, - { title: 'Desk' }, - { title: 'Dress' }, - ]), Tag.bulkCreate([ - { name: 'A' }, - { name: 'B' }, - { name: 'C' }, - ])]); + await Promise.all([ + Set.bulkCreate([ + { title: 'office' }, + ]), + Product.bulkCreate([ + { title: 'Chair' }, + { title: 'Desk' }, + { title: 'Dress' }, + ]), + Tag.bulkCreate([ + { name: 'A' }, + { name: 'B' }, + { name: 'C' }, + ]), + ]); const [sets, products, tags] = await Promise.all([Set.findAll(), Product.findAll(), Tag.findAll()]); await Promise.all([ sets[0].addProducts([products[0], products[1]]), - products[0].addTag(tags[0], { priority: 1 }).then(() => { - return products[0].addTag(tags[1], { priority: 2 }); - }).then(() => { - return products[0].addTag(tags[2], { priority: 1 }); - }), - products[1].addTag(tags[1], { priority: 2 }).then(() => { - return products[2].addTag(tags[1], { priority: 3 }); - }).then(() => { - return products[2].addTag(tags[2], { priority: 0 }); - }), + products[0].addTag(tags[0], { priority: 1 }) + .then(() => { + return products[0].addTag(tags[1], { priority: 2 }); + }) + .then(() => { + return products[0].addTag(tags[2], { priority: 1 }); + }), + products[1].addTag(tags[1], { priority: 2 }) + .then(() => { + return products[2].addTag(tags[1], { priority: 3 }); + }) + .then(() => { + return products[2].addTag(tags[2], { priority: 0 }); + }), ]); await Set.findAll({ @@ -361,8 +368,8 @@ describe(Support.getTestDialectTeaser('Include'), () => { ]); await Promise.all([ GroupMember.bulkCreate([ - { UserId: user.id, GroupId: groups[0].id, RankId: ranks[0].id }, - { UserId: user.id, GroupId: groups[1].id, RankId: ranks[1].id }, + { userId: user.id, groupId: groups[0].id, rankId: ranks[0].id }, + { userId: user.id, groupId: groups[1].id, rankId: ranks[1].id }, ]), user.setProducts([ products[i * 2 + 0], @@ -377,12 +384,12 @@ describe(Support.getTestDialectTeaser('Include'), () => { ]), products[i * 2 + 0].setCategory(tags[1]), Price.bulkCreate([ - { ProductId: products[i * 2 + 0].id, value: 5 }, - { ProductId: products[i * 2 + 0].id, value: 10 }, - { ProductId: products[i * 2 + 1].id, value: 5 }, - { ProductId: products[i * 2 + 1].id, value: 10 }, - { ProductId: products[i * 2 + 1].id, value: 15 }, - { ProductId: products[i * 2 + 1].id, value: 20 }, + { productId: products[i * 2 + 0].id, value: 5 }, + { productId: products[i * 2 + 0].id, value: 10 }, + { productId: products[i * 2 + 1].id, value: 5 }, + { productId: products[i * 2 + 1].id, value: 10 }, + { productId: products[i * 2 + 1].id, value: 15 }, + { productId: products[i * 2 + 1].id, value: 20 }, ]), ]); const users = await User.findAll({ @@ -398,7 +405,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { { model: Product, include: [ - 'Tags', + 'tags', { model: Tag, as: 'Category' }, Price, ], @@ -412,20 +419,20 @@ describe(Support.getTestDialectTeaser('Include'), () => { user.Memberships.sort(sortById); expect(user.Memberships.length).to.equal(2); - expect(user.Memberships[0].Group.name).to.equal('Developers'); - expect(user.Memberships[0].Rank.canRemove).to.equal(1); - expect(user.Memberships[1].Group.name).to.equal('Designers'); - expect(user.Memberships[1].Rank.canRemove).to.equal(0); - - user.Products.sort(sortById); - expect(user.Products.length).to.equal(2); - expect(user.Products[0].Tags.length).to.equal(2); - expect(user.Products[1].Tags.length).to.equal(1); - expect(user.Products[0].Category).to.be.ok; - expect(user.Products[1].Category).not.to.be.ok; - - expect(user.Products[0].Prices.length).to.equal(2); - expect(user.Products[1].Prices.length).to.equal(4); + expect(user.Memberships[0].group.name).to.equal('Developers'); + expect(user.Memberships[0].rank.canRemove).to.equal(1); + expect(user.Memberships[1].group.name).to.equal('Designers'); + expect(user.Memberships[1].rank.canRemove).to.equal(0); + + user.products.sort(sortById); + expect(user.products.length).to.equal(2); + expect(user.products[0].tags.length).to.equal(2); + expect(user.products[1].tags.length).to.equal(1); + expect(user.products[0].Category).to.be.ok; + expect(user.products[1].Category).not.to.be.ok; + + expect(user.products[0].prices.length).to.equal(2); + expect(user.products[1].prices.length).to.equal(4); } } }); @@ -712,8 +719,8 @@ describe(Support.getTestDialectTeaser('Include'), () => { expect(as[0].itemA.test).to.eql('abc'); expect(as[1].itemA.test).to.eql('abc'); - expect(as[0].Order.position).to.eql(1); - expect(as[1].Order.position).to.eql(2); + expect(as[0].order.position).to.eql(1); + expect(as[1].order.position).to.eql(2); }); it('should include attributes from through models', async function () { @@ -768,14 +775,14 @@ describe(Support.getTestDialectTeaser('Include'), () => { ], }); - expect(products[0].Tags[0].ProductTag.priority).to.equal(1); - expect(products[0].Tags[1].ProductTag.priority).to.equal(2); + expect(products[0].tags[0].ProductTag.priority).to.equal(1); + expect(products[0].tags[1].ProductTag.priority).to.equal(2); - expect(products[1].Tags[0].ProductTag.priority).to.equal(1); + expect(products[1].tags[0].ProductTag.priority).to.equal(1); - expect(products[2].Tags[0].ProductTag.priority).to.equal(3); - expect(products[2].Tags[1].ProductTag.priority).to.equal(1); - expect(products[2].Tags[2].ProductTag.priority).to.equal(2); + expect(products[2].tags[0].ProductTag.priority).to.equal(3); + expect(products[2].tags[1].ProductTag.priority).to.equal(1); + expect(products[2].tags[2].ProductTag.priority).to.equal(2); }); it('should support a required belongsTo include', async function () { @@ -804,7 +811,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { }); expect(users.length).to.equal(1); - expect(users[0].Group).to.be.ok; + expect(users[0].group).to.be.ok; }); it('should be possible to extend the on clause with a where option on a belongsTo include', async function () { @@ -841,8 +848,8 @@ describe(Support.getTestDialectTeaser('Include'), () => { }); expect(users.length).to.equal(1); - expect(users[0].Group).to.be.ok; - expect(users[0].Group.name).to.equal('A'); + expect(users[0].group).to.be.ok; + expect(users[0].group.name).to.equal('A'); }); it('should be possible to extend the on clause with a where option on a belongsTo include', async function () { @@ -879,7 +886,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { }); for (const user of users) { - expect(user.Group).to.be.ok; + expect(user.group).to.be.ok; } }); @@ -916,8 +923,8 @@ describe(Support.getTestDialectTeaser('Include'), () => { }], }); - expect(john.Address).to.be.ok; - expect(john.Address.Street).to.be.ok; + expect(john.address).to.be.ok; + expect(john.address.street).to.be.ok; }); it('should be possible to define a belongsTo include as required with child hasMany with limit', async function () { @@ -970,8 +977,8 @@ describe(Support.getTestDialectTeaser('Include'), () => { expect(users.length).to.equal(1); for (const user of users) { - expect(user.Group).to.be.ok; - expect(user.Group.Categories).to.be.ok; + expect(user.group).to.be.ok; + expect(user.group.categories).to.be.ok; } }); @@ -1080,8 +1087,8 @@ describe(Support.getTestDialectTeaser('Include'), () => { expect(users.length).to.equal(1); for (const user of users) { - expect(user.Group).to.be.ok; - expect(user.Group.Categories).to.be.ok; + expect(user.group).to.be.ok; + expect(user.group.categories).to.be.ok; } }); @@ -1172,7 +1179,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { }); expect(products.length).to.equal(1); - expect(products[0].Tags.length).to.equal(1); + expect(products[0].tags.length).to.equal(1); }); it('should be possible to extend the on clause with a where option on nested includes', async function () { @@ -1247,8 +1254,8 @@ describe(Support.getTestDialectTeaser('Include'), () => { const products = await Product.findAll(); await Promise.all([ GroupMember.bulkCreate([ - { UserId: user.id, GroupId: groups[0].id, RankId: ranks[0].id }, - { UserId: user.id, GroupId: groups[1].id, RankId: ranks[1].id }, + { userId: user.id, groupId: groups[0].id, rankId: ranks[0].id }, + { userId: user.id, groupId: groups[1].id, rankId: ranks[1].id }, ]), user.setProducts([ products[i * 2 + 0], @@ -1263,12 +1270,12 @@ describe(Support.getTestDialectTeaser('Include'), () => { ]), products[i * 2 + 0].setCategory(tags[1]), Price.bulkCreate([ - { ProductId: products[i * 2 + 0].id, value: 5 }, - { ProductId: products[i * 2 + 0].id, value: 10 }, - { ProductId: products[i * 2 + 1].id, value: 5 }, - { ProductId: products[i * 2 + 1].id, value: 10 }, - { ProductId: products[i * 2 + 1].id, value: 15 }, - { ProductId: products[i * 2 + 1].id, value: 20 }, + { productId: products[i * 2 + 0].id, value: 5 }, + { productId: products[i * 2 + 0].id, value: 10 }, + { productId: products[i * 2 + 1].id, value: 5 }, + { productId: products[i * 2 + 1].id, value: 10 }, + { productId: products[i * 2 + 1].id, value: 15 }, + { productId: products[i * 2 + 1].id, value: 20 }, ]), ]); } @@ -1286,7 +1293,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { { model: Product, include: [ - 'Tags', + 'tags', { model: Tag, as: 'Category' }, { model: Price, @@ -1305,9 +1312,9 @@ describe(Support.getTestDialectTeaser('Include'), () => { }); for (const user of users) { expect(user.Memberships.length).to.equal(1); - expect(user.Memberships[0].Rank.name).to.equal('Admin'); - expect(user.Products.length).to.equal(1); - expect(user.Products[0].Prices.length).to.equal(1); + expect(user.Memberships[0].rank.name).to.equal('Admin'); + expect(user.products.length).to.equal(1); + expect(user.products[0].prices.length).to.equal(1); } }); @@ -1350,7 +1357,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { expect(users.length).to.equal(2); for (const user of users) { - expect(user.Group.name).to.equal('A'); + expect(user.group.name).to.equal('A'); } }); @@ -1361,7 +1368,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { attributes: ['id', 'title'], include: [ { model: this.models.Company, where: { name: 'NYSE' } }, - { model: this.models.Tag, as: 'Tags' }, + { model: this.models.Tag, as: 'tags' }, { model: this.models.Price }, ], limit: 3, @@ -1373,9 +1380,9 @@ describe(Support.getTestDialectTeaser('Include'), () => { expect(products.length).to.equal(3); for (const product of products) { - expect(product.Company.name).to.equal('NYSE'); - expect(product.Tags.length).to.be.ok; - expect(product.Prices.length).to.be.ok; + expect(product.company.name).to.equal('NYSE'); + expect(product.tags.length).to.be.ok; + expect(product.prices.length).to.be.ok; } }); @@ -1415,13 +1422,13 @@ describe(Support.getTestDialectTeaser('Include'), () => { const products = await this.models.Product.findAll({ attributes: ['title'], include: [ - { model: this.models.Tag, as: 'Tags', through: { attributes: [] }, required: true }, + { model: this.models.Tag, as: 'tags', through: { attributes: [] }, required: true }, ], }); for (const product of products) { - expect(product.Tags.length).to.be.ok; - for (const tag of product.Tags) { + expect(product.tags.length).to.be.ok; + for (const tag of product.tags) { expect(tag.get().productTags).not.to.be.ok; } } @@ -1435,10 +1442,10 @@ describe(Support.getTestDialectTeaser('Include'), () => { include: [ { model: this.models.Tag, - as: 'Tags', + as: 'tags', through: { where: { - ProductId: 3, + productId: 3, }, }, required: true, @@ -1457,10 +1464,10 @@ describe(Support.getTestDialectTeaser('Include'), () => { include: [ { model: this.models.Tag, - as: 'Tags', + as: 'tags', through: { where: { - ProductId: 3, + productId: 3, }, }, required: true, @@ -1520,7 +1527,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { }); albums.push({ title: `Album${i}`, - MemberId: i, + memberId: i, }); } @@ -1539,7 +1546,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { expect(members0.length).to.equal(20); for (const member of members0) { expect(member.get('id')).not.to.be.ok; - expect(member.Albums.length).to.equal(1); + expect(member.albums.length).to.equal(1); } }); @@ -1549,9 +1556,10 @@ describe(Support.getTestDialectTeaser('Include'), () => { const products = await this.models.Product.findAll({ include: [ { model: this.models.Company }, - { model: this.models.Tag, as: 'Tags' }, + { model: this.models.Tag, as: 'tags' }, { - model: this.models.Price, where: { + model: this.models.Price, + where: { value: { [Op.gt]: 5 }, }, }, @@ -1565,10 +1573,10 @@ describe(Support.getTestDialectTeaser('Include'), () => { expect(products.length).to.equal(6); for (const product of products) { - expect(product.Tags.length).to.be.ok; - expect(product.Prices.length).to.be.ok; + expect(product.tags.length).to.be.ok; + expect(product.prices.length).to.be.ok; - for (const price of product.Prices) { + for (const price of product.prices) { expect(price.value).to.be.above(5); } } @@ -1580,7 +1588,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { const products = await this.models.Product.findAll({ include: [ { model: this.models.Company }, - { model: this.models.Tag, as: 'Tags', where: { name: ['A', 'B', 'C'] } }, + { model: this.models.Tag, as: 'tags', where: { name: ['A', 'B', 'C'] } }, { model: this.models.Price }, ], limit: 10, @@ -1592,10 +1600,10 @@ describe(Support.getTestDialectTeaser('Include'), () => { expect(products.length).to.equal(10); for (const product of products) { - expect(product.Tags.length).to.be.ok; - expect(product.Prices.length).to.be.ok; + expect(product.tags.length).to.be.ok; + expect(product.prices.length).to.be.ok; - for (const tag of product.Tags) { + for (const tag of product.tags) { expect(['A', 'B', 'C']).to.include(tag.name); } } @@ -1707,7 +1715,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { }); const UserPerson = this.sequelize.define('UserPerson', { - PersonId: { + personId: { type: DataTypes.INTEGER, primaryKey: true, }, @@ -1718,7 +1726,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { }); const User = this.sequelize.define('User', { - UserPersonId: { + userPersonId: { type: DataTypes.INTEGER, primaryKey: true, }, @@ -1745,14 +1753,14 @@ describe(Support.getTestDialectTeaser('Include'), () => { User.belongsTo(UserPerson, { foreignKey: { - name: 'UserPersonId', + name: 'userPersonId', allowNull: false, onDelete: 'CASCADE', }, }); UserPerson.hasOne(User, { foreignKey: { - name: 'UserPersonId', + name: 'userPersonId', allowNull: false, onDelete: 'CASCADE', }, @@ -1835,13 +1843,13 @@ describe(Support.getTestDialectTeaser('Include'), () => { }); expect(users[0].lastName).to.equal('Albertsen'); - expect(users[0].Company.rank).to.equal(1); + expect(users[0].company.rank).to.equal(1); expect(users[1].lastName).to.equal('Zenith'); - expect(users[1].Company.rank).to.equal(2); + expect(users[1].company.rank).to.equal(2); expect(users[2].lastName).to.equal('Hansen'); - expect(users[2].Company.rank).to.equal(2); + expect(users[2].company.rank).to.equal(2); }); it('should ignore include with attributes: [] (used for aggregates)', async function () { @@ -2055,10 +2063,10 @@ describe(Support.getTestDialectTeaser('Include'), () => { }); expect(posts.length).to.equal(1); - expect(posts[0].Entity.creator).to.equal('bob'); - expect(posts[0].Entity.tags.length).to.equal(1); - expect(posts[0].Entity.tags[0].EntityTag.tag_name).to.equal('bob'); - expect(posts[0].Entity.tags[0].EntityTag.entity_id).to.equal(posts[0].post_id); + expect(posts[0].entity.creator).to.equal('bob'); + expect(posts[0].entity.tags.length).to.equal(1); + expect(posts[0].entity.tags[0].EntityTag.tag_name).to.equal('bob'); + expect(posts[0].entity.tags[0].EntityTag.entity_id).to.equal(posts[0].post_id); }); it('should be able to generate a correct request with inner and outer join', async function () { @@ -2122,10 +2130,10 @@ describe(Support.getTestDialectTeaser('Include'), () => { for (const product of products) { expect(product.title).to.be.a('string'); // checking that internally added fields used to handle 'BelongsTo' associations are not leaked to result - expect(product.UserId).to.equal(undefined); + expect(product.userId).to.equal(undefined); // checking that included models are on their places - expect(product.User).to.satisfy(User => User === null || User instanceof this.models.User); - expect(product.Prices).to.be.an('array'); + expect(product.user).to.satisfy(User => User === null || User instanceof this.models.User); + expect(product.prices).to.be.an('array'); } }); diff --git a/packages/core/test/integration/include/findAndCountAll.test.js b/packages/core/test/integration/include/findAndCountAll.test.js index af20a887b01c..db3619a60263 100644 --- a/packages/core/test/integration/include/findAndCountAll.test.js +++ b/packages/core/test/integration/include/findAndCountAll.test.js @@ -182,13 +182,11 @@ describe(Support.getTestDialectTeaser('Include'), () => { User.hasMany(Project); - let userId = null; - await User.sync({ force: true }); await Project.sync({ force: true }); const results = await Promise.all([User.create(), Project.create(), Project.create(), Project.create()]); const user = results[0]; - userId = user.id; + const userId = user.id; await user.setProjects([results[1], results[2], results[3]]); const result = await User.findAndCountAll({ @@ -198,7 +196,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { }); expect(result.rows.length).to.equal(1); - expect(result.rows[0].Projects.length).to.equal(3); + expect(result.rows[0].projects.length).to.equal(3); expect(result.count).to.equal(1); }); @@ -214,7 +212,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { // Make five instances of Foo await Foo.bulkCreate([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]); // Make four instances of Bar, related to the last four instances of Foo - await Bar.bulkCreate([{ FooId: 2 }, { FooId: 3 }, { FooId: 4 }, { FooId: 5 }]); + await Bar.bulkCreate([{ fooId: 2 }, { fooId: 3 }, { fooId: 4 }, { fooId: 5 }]); // Query for the first two instances of Foo which have related Bars const result0 = await Foo.findAndCountAll({ @@ -247,7 +245,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { await this.sequelize.sync({ force: true }); await Foo.bulkCreate([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]); // Make four instances of Bar, related to the first two instances of Foo - await Bar.bulkCreate([{ FooId: 1, m: 'yes' }, { FooId: 1, m: 'yes' }, { FooId: 1, m: 'no' }, { FooId: 2, m: 'yes' }]); + await Bar.bulkCreate([{ fooId: 1, m: 'yes' }, { fooId: 1, m: 'yes' }, { fooId: 1, m: 'no' }, { fooId: 2, m: 'yes' }]); // Query for the first instance of Foo which have related Bars with m === 'yes' const result = await Foo.findAndCountAll({ @@ -302,15 +300,15 @@ describe(Support.getTestDialectTeaser('Include'), () => { ]); await Project.bulkCreate([ - { m: 'A', UserId: 1 }, - { m: 'A', UserId: 2 }, + { m: 'A', userId: 1 }, + { m: 'A', userId: 2 }, ]); await Task.bulkCreate([ - { ProjectId: 1, name: 'Just' }, - { ProjectId: 1, name: 'for' }, - { ProjectId: 2, name: 'testing' }, - { ProjectId: 2, name: 'proposes' }, + { projectId: 1, name: 'Just' }, + { projectId: 1, name: 'for' }, + { projectId: 2, name: 'testing' }, + { projectId: 2, name: 'proposes' }, ]); // Find All Tasks with Project(m=a) and User(name=user-name-2) @@ -360,9 +358,9 @@ describe(Support.getTestDialectTeaser('Include'), () => { ]); await Project.bulkCreate([ - { name: 'naam-satya', UserId: 1 }, - { name: 'guru-satya', UserId: 2 }, - { name: 'app-satya', UserId: 2 }, + { name: 'naam-satya', userId: 1 }, + { name: 'guru-satya', userId: 2 }, + { name: 'app-satya', userId: 2 }, ]); const result = await User.findAndCountAll({ diff --git a/packages/core/test/integration/include/findOne.test.js b/packages/core/test/integration/include/findOne.test.js index a569259775c9..94edca357592 100644 --- a/packages/core/test/integration/include/findOne.test.js +++ b/packages/core/test/integration/include/findOne.test.js @@ -98,7 +98,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { }); expect(user).to.be.ok; - expect(user.Tasks.length).to.equal(0); + expect(user.tasks.length).to.equal(0); }); it('should include a model with a where clause when the PK field name and attribute name are different', async function () { @@ -135,7 +135,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { }); expect(user).to.be.ok; - expect(user.Tasks.length).to.equal(1); + expect(user.tasks.length).to.equal(1); }); it('should include a model with a through.where and required true clause when the PK field name and attribute name are different', async function () { @@ -253,7 +253,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { }); expect(foundTask).to.be.ok; - expect(foundTask.User.username).to.equal('bob'); + expect(foundTask.user.username).to.equal('bob'); }); it('should support many levels of belongsTo (with a lower level having a where)', async function () { diff --git a/packages/core/test/integration/include/limit.test.js b/packages/core/test/integration/include/limit.test.js index 5c8126241a63..b72f32e123af 100644 --- a/packages/core/test/integration/include/limit.test.js +++ b/packages/core/test/integration/include/limit.test.js @@ -251,7 +251,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { required: true, through: { where: { - HobbyName: 'archery', + hobbyName: 'archery', }, }, }], @@ -634,7 +634,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { required: true, through: { where: { - HobbyName: 'archery', + hobbyName: 'archery', }, }, }], diff --git a/packages/core/test/integration/include/schema.test.js b/packages/core/test/integration/include/schema.test.js index f91b00f10b50..7339fcc56ad6 100644 --- a/packages/core/test/integration/include/schema.test.js +++ b/packages/core/test/integration/include/schema.test.js @@ -129,11 +129,11 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { ]).then(() => Product.findAll()), ]); const groupMembers = [ - { AccUserId: user.id, GroupId: groups[0].id, RankId: ranks[0].id }, - { AccUserId: user.id, GroupId: groups[1].id, RankId: ranks[2].id }, + { accUserId: user.id, GroupId: groups[0].id, rankId: ranks[0].id }, + { accUserId: user.id, GroupId: groups[1].id, rankId: ranks[2].id }, ]; if (i < 3) { - groupMembers.push({ AccUserId: user.id, GroupId: groups[2].id, RankId: ranks[1].id }); + groupMembers.push({ accUserId: user.id, GroupId: groups[2].id, rankId: ranks[1].id }); } await Promise.all([ @@ -163,14 +163,14 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { products[i * 5 + 3].setCompany(companies[1]), products[i * 5 + 4].setCompany(companies[0]), Price.bulkCreate([ - { ProductId: products[i * 5 + 0].id, value: 5 }, - { ProductId: products[i * 5 + 0].id, value: 10 }, - { ProductId: products[i * 5 + 1].id, value: 5 }, - { ProductId: products[i * 5 + 1].id, value: 10 }, - { ProductId: products[i * 5 + 1].id, value: 15 }, - { ProductId: products[i * 5 + 1].id, value: 20 }, - { ProductId: products[i * 5 + 2].id, value: 20 }, - { ProductId: products[i * 5 + 3].id, value: 20 }, + { productId: products[i * 5 + 0].id, value: 5 }, + { productId: products[i * 5 + 0].id, value: 10 }, + { productId: products[i * 5 + 1].id, value: 5 }, + { productId: products[i * 5 + 1].id, value: 10 }, + { productId: products[i * 5 + 1].id, value: 15 }, + { productId: products[i * 5 + 1].id, value: 20 }, + { productId: products[i * 5 + 2].id, value: 20 }, + { productId: products[i * 5 + 3].id, value: 20 }, ]), ]); } @@ -250,8 +250,8 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { ]); await Promise.all([ GroupMember.bulkCreate([ - { AccUserId: user.id, GroupId: groups[0].id, RankId: ranks[0].id }, - { AccUserId: user.id, GroupId: groups[1].id, RankId: ranks[1].id }, + { accUserId: user.id, groupId: groups[0].id, rankId: ranks[0].id }, + { accUserId: user.id, groupId: groups[1].id, rankId: ranks[1].id }, ]), user.setProducts([ products[i * 2 + 0], @@ -266,12 +266,12 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { ]), products[i * 2 + 0].setCategory(tags[1]), Price.bulkCreate([ - { ProductId: products[i * 2 + 0].id, value: 5 }, - { ProductId: products[i * 2 + 0].id, value: 10 }, - { ProductId: products[i * 2 + 1].id, value: 5 }, - { ProductId: products[i * 2 + 1].id, value: 10 }, - { ProductId: products[i * 2 + 1].id, value: 15 }, - { ProductId: products[i * 2 + 1].id, value: 20 }, + { productId: products[i * 2 + 0].id, value: 5 }, + { productId: products[i * 2 + 0].id, value: 10 }, + { productId: products[i * 2 + 1].id, value: 5 }, + { productId: products[i * 2 + 1].id, value: 10 }, + { productId: products[i * 2 + 1].id, value: 15 }, + { productId: products[i * 2 + 1].id, value: 20 }, ]), ]); @@ -288,7 +288,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { { model: Product, include: [ - 'Tags', + 'tags', { model: Tag, as: 'Category' }, Price, ], @@ -304,20 +304,20 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { user.Memberships.sort(sortById); expect(user.Memberships.length).to.equal(2); - expect(user.Memberships[0].Group.name).to.equal('Developers'); - expect(user.Memberships[0].Rank.canRemove).to.equal(1); - expect(user.Memberships[1].Group.name).to.equal('Designers'); - expect(user.Memberships[1].Rank.canRemove).to.equal(0); - - user.Products.sort(sortById); - expect(user.Products.length).to.equal(2); - expect(user.Products[0].Tags.length).to.equal(2); - expect(user.Products[1].Tags.length).to.equal(1); - expect(user.Products[0].Category).to.be.ok; - expect(user.Products[1].Category).not.to.be.ok; - - expect(user.Products[0].Prices.length).to.equal(2); - expect(user.Products[1].Prices.length).to.equal(4); + expect(user.Memberships[0].group.name).to.equal('Developers'); + expect(user.Memberships[0].rank.canRemove).to.equal(1); + expect(user.Memberships[1].group.name).to.equal('Designers'); + expect(user.Memberships[1].rank.canRemove).to.equal(0); + + user.products.sort(sortById); + expect(user.products.length).to.equal(2); + expect(user.products[0].tags.length).to.equal(2); + expect(user.products[1].tags.length).to.equal(1); + expect(user.products[0].Category).to.be.ok; + expect(user.products[1].Category).not.to.be.ok; + + expect(user.products[0].prices.length).to.equal(2); + expect(user.products[1].prices.length).to.equal(4); } } }); @@ -461,8 +461,8 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { expect(as.length).to.eql(2); expect(as[0].itemA.test).to.eql('abc'); expect(as[1].itemA.test).to.eql('abc'); - expect(as[0].Order.position).to.eql(1); - expect(as[1].Order.position).to.eql(2); + expect(as[0].order.position).to.eql(1); + expect(as[1].order.position).to.eql(2); }); it('should include attributes from through models', async function () { @@ -518,12 +518,12 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { ], }); - expect(products[0].Tags[0].ProductTag.priority).to.equal(1); - expect(products[0].Tags[1].ProductTag.priority).to.equal(2); - expect(products[1].Tags[0].ProductTag.priority).to.equal(1); - expect(products[2].Tags[0].ProductTag.priority).to.equal(3); - expect(products[2].Tags[1].ProductTag.priority).to.equal(1); - expect(products[2].Tags[2].ProductTag.priority).to.equal(2); + expect(products[0].tags[0].ProductTag.priority).to.equal(1); + expect(products[0].tags[1].ProductTag.priority).to.equal(2); + expect(products[1].tags[0].ProductTag.priority).to.equal(1); + expect(products[2].tags[0].ProductTag.priority).to.equal(3); + expect(products[2].tags[1].ProductTag.priority).to.equal(1); + expect(products[2].tags[2].ProductTag.priority).to.equal(2); }); it('should support a required belongsTo include', async function () { @@ -553,7 +553,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { }); expect(users.length).to.equal(1); - expect(users[0].Group).to.be.ok; + expect(users[0].group).to.be.ok; }); it('should be possible to extend the on clause with a where option on a belongsTo include', async function () { @@ -591,8 +591,8 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { }); expect(users.length).to.equal(1); - expect(users[0].Group).to.be.ok; - expect(users[0].Group.name).to.equal('A'); + expect(users[0].group).to.be.ok; + expect(users[0].group.name).to.equal('A'); }); it('should be possible to extend the on clause with a where option on a belongsTo include', async function () { @@ -630,7 +630,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { }); for (const user of users) { - expect(user.Group).to.be.ok; + expect(user.group).to.be.ok; } }); @@ -686,8 +686,8 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { expect(users.length).to.equal(1); for (const user of users) { - expect(user.Group).to.be.ok; - expect(user.Group.Categories).to.be.ok; + expect(user.group).to.be.ok; + expect(user.group.categories).to.be.ok; } }); @@ -800,8 +800,8 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { expect(users.length).to.equal(1); for (const user of users) { - expect(user.Group).to.be.ok; - expect(user.Group.Categories).to.be.ok; + expect(user.group).to.be.ok; + expect(user.group.categories).to.be.ok; } }); @@ -894,7 +894,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { }); expect(products.length).to.equal(1); - expect(products[0].Tags.length).to.equal(1); + expect(products[0].tags.length).to.equal(1); }); it('should be possible to extend the on clause with a where option on nested includes', async function () { @@ -968,8 +968,8 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { ]); await Promise.all([ GroupMember.bulkCreate([ - { UserId: user.id, GroupId: groups[0].id, RankId: ranks[0].id }, - { UserId: user.id, GroupId: groups[1].id, RankId: ranks[1].id }, + { userId: user.id, groupId: groups[0].id, rankId: ranks[0].id }, + { userId: user.id, groupId: groups[1].id, rankId: ranks[1].id }, ]), user.setProducts([ products[i * 2 + 0], @@ -984,14 +984,15 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { ]), products[i * 2 + 0].setCategory(tags[1]), Price.bulkCreate([ - { ProductId: products[i * 2 + 0].id, value: 5 }, - { ProductId: products[i * 2 + 0].id, value: 10 }, - { ProductId: products[i * 2 + 1].id, value: 5 }, - { ProductId: products[i * 2 + 1].id, value: 10 }, - { ProductId: products[i * 2 + 1].id, value: 15 }, - { ProductId: products[i * 2 + 1].id, value: 20 }, + { productId: products[i * 2 + 0].id, value: 5 }, + { productId: products[i * 2 + 0].id, value: 10 }, + { productId: products[i * 2 + 1].id, value: 5 }, + { productId: products[i * 2 + 1].id, value: 10 }, + { productId: products[i * 2 + 1].id, value: 15 }, + { productId: products[i * 2 + 1].id, value: 20 }, ]), ]); + const users = await User.findAll({ include: [ { @@ -1005,7 +1006,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { { model: Product, include: [ - 'Tags', + 'tags', { model: Tag, as: 'Category' }, { model: Price, @@ -1024,9 +1025,9 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { }); for (const user of users) { expect(user.Memberships.length).to.equal(1); - expect(user.Memberships[0].Rank.name).to.equal('Admin'); - expect(user.Products.length).to.equal(1); - expect(user.Products[0].Prices.length).to.equal(1); + expect(user.Memberships[0].rank.name).to.equal('Admin'); + expect(user.products.length).to.equal(1); + expect(user.products[0].prices.length).to.equal(1); } } }); @@ -1070,7 +1071,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { expect(users.length).to.equal(2); for (const user of users) { - expect(user.Group.name).to.equal('A'); + expect(user.group.name).to.equal('A'); } }); @@ -1081,7 +1082,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { attributes: ['title'], include: [ { model: this.models.Company, where: { name: 'NYSE' } }, - { model: this.models.Tag, as: 'Tags' }, + { model: this.models.Tag, as: 'tags' }, { model: this.models.Price }, ], limit: 3, @@ -1093,9 +1094,9 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { expect(products.length).to.equal(3); for (const product of products) { - expect(product.Company.name).to.equal('NYSE'); - expect(product.Tags.length).to.be.ok; - expect(product.Prices.length).to.be.ok; + expect(product.company.name).to.equal('NYSE'); + expect(product.tags.length).to.be.ok; + expect(product.prices.length).to.be.ok; } }); @@ -1105,7 +1106,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { const products = await this.models.Product.findAll({ include: [ { model: this.models.Company }, - { model: this.models.Tag, as: 'Tags' }, + { model: this.models.Tag, as: 'tags' }, { model: this.models.Price, where: { @@ -1122,10 +1123,10 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { expect(products.length).to.equal(6); for (const product of products) { - expect(product.Tags.length).to.be.ok; - expect(product.Prices.length).to.be.ok; + expect(product.tags.length).to.be.ok; + expect(product.prices.length).to.be.ok; - for (const price of product.Prices) { + for (const price of product.prices) { expect(price.value).to.be.above(5); } } @@ -1137,7 +1138,7 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { const products = await this.models.Product.findAll({ include: [ { model: this.models.Company }, - { model: this.models.Tag, as: 'Tags', where: { name: ['A', 'B', 'C'] } }, + { model: this.models.Tag, as: 'tags', where: { name: ['A', 'B', 'C'] } }, { model: this.models.Price }, ], limit: 10, @@ -1149,10 +1150,10 @@ describe(Support.getTestDialectTeaser('Includes with schemas'), () => { expect(products.length).to.equal(10); for (const product of products) { - expect(product.Tags.length).to.be.ok; - expect(product.Prices.length).to.be.ok; + expect(product.tags.length).to.be.ok; + expect(product.prices.length).to.be.ok; - for (const tag of product.Tags) { + for (const tag of product.tags) { expect(['A', 'B', 'C']).to.include(tag.name); } } diff --git a/packages/core/test/integration/include/separate.test.js b/packages/core/test/integration/include/separate.test.js index 1f262869d2bc..be3c28b9fc80 100644 --- a/packages/core/test/integration/include/separate.test.js +++ b/packages/core/test/integration/include/separate.test.js @@ -506,7 +506,7 @@ if (current.dialect.supports.groupedLimit) { required: true, include: [{ association: User.Tasks, - attributes: ['UserId'], + attributes: ['userId'], separate: true, include: [{ association: Task.User, @@ -522,10 +522,10 @@ if (current.dialect.supports.groupedLimit) { expect(results.length).to.equal(1); expect(results[0].id).to.equal(1); - expect(results[0].User.id).to.equal(2); - expect(results[0].User.Tasks.length).to.equal(1); - expect(results[0].User.Tasks[0].User.id).to.equal(2); - expect(results[0].User.Tasks[0].User.Company.id).to.equal(3); + expect(results[0].user.id).to.equal(2); + expect(results[0].user.tasks.length).to.equal(1); + expect(results[0].user.tasks[0].user.id).to.equal(2); + expect(results[0].user.tasks[0].user.company.id).to.equal(3); }); }); }); diff --git a/packages/core/test/integration/model.test.js b/packages/core/test/integration/model.test.js index f9e560c3c7d9..36ba1733f6d2 100644 --- a/packages/core/test/integration/model.test.js +++ b/packages/core/test/integration/model.test.js @@ -648,11 +648,11 @@ describe(Support.getTestDialectTeaser('Model'), () => { const product = Product.build({ id: 1, title: 'Chair', - Tags: [ + tags: [ { id: 1, name: 'Alpha' }, { id: 2, name: 'Beta' }, ], - User: { + user: { id: 1, first_name: 'Mick', last_name: 'Hansen', @@ -664,11 +664,11 @@ describe(Support.getTestDialectTeaser('Model'), () => { ], }); - expect(product.Tags).to.be.ok; - expect(product.Tags.length).to.equal(2); - expect(product.Tags[0]).to.be.instanceof(Tag); - expect(product.User).to.be.ok; - expect(product.User).to.be.instanceof(User); + expect(product.tags).to.be.ok; + expect(product.tags.length).to.equal(2); + expect(product.tags[0]).to.be.instanceof(Tag); + expect(product.user).to.be.ok; + expect(product.user).to.be.instanceof(User); }); it('should support includes with aliases', function () { @@ -1429,7 +1429,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { it('should not fail with an include', async function () { const users = await this.User.findAll({ - where: this.sequelize.literal(`${this.sequelize.queryGenerator.quoteIdentifiers('Projects.title')} = ${this.sequelize.queryGenerator.escape('republic')}`), + where: this.sequelize.literal(`${this.sequelize.queryGenerator.quoteIdentifiers('projects.title')} = ${this.sequelize.queryGenerator.escape('republic')}`), include: [ { model: this.Project }, ], diff --git a/packages/core/test/integration/model/bulk-create/include.test.js b/packages/core/test/integration/model/bulk-create/include.test.js index 4f1ece107a3a..e9e052d9491a 100644 --- a/packages/core/test/integration/model/bulk-create/include.test.js +++ b/packages/core/test/integration/model/bulk-create/include.test.js @@ -16,7 +16,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { hooks: { afterBulkCreate(products) { for (const product of products) { - product.isIncludeCreatedOnAfterCreate = Boolean(product.User && product.User.id); + product.isIncludeCreatedOnAfterCreate = Boolean(product.user && product.user.id); } }, }, @@ -40,13 +40,13 @@ describe(Support.getTestDialectTeaser('Model'), () => { const savedProducts = await Product.bulkCreate([{ title: 'Chair', - User: { + user: { first_name: 'Mick', last_name: 'Broadstone', }, }, { title: 'Table', - User: { + user: { first_name: 'John', last_name: 'Johnson', }, @@ -58,10 +58,10 @@ describe(Support.getTestDialectTeaser('Model'), () => { }); expect(savedProducts[0].isIncludeCreatedOnAfterCreate).to.be.true; - expect(savedProducts[0].User.createOptions.myOption).to.equal('option'); + expect(savedProducts[0].user.createOptions.myOption).to.equal('option'); expect(savedProducts[1].isIncludeCreatedOnAfterCreate).to.be.true; - expect(savedProducts[1].User.createOptions.myOption).to.equal('option'); + expect(savedProducts[1].user.createOptions.myOption).to.equal('option'); const persistedProducts = await Promise.all([ Product.findOne({ @@ -74,13 +74,13 @@ describe(Support.getTestDialectTeaser('Model'), () => { }), ]); - expect(persistedProducts[0].User).to.be.ok; - expect(persistedProducts[0].User.first_name).to.equal('Mick'); - expect(persistedProducts[0].User.last_name).to.equal('Broadstone'); + expect(persistedProducts[0].user).to.be.ok; + expect(persistedProducts[0].user.first_name).to.equal('Mick'); + expect(persistedProducts[0].user.last_name).to.equal('Broadstone'); - expect(persistedProducts[1].User).to.be.ok; - expect(persistedProducts[1].User.first_name).to.equal('John'); - expect(persistedProducts[1].User.last_name).to.equal('Johnson'); + expect(persistedProducts[1].user).to.be.ok; + expect(persistedProducts[1].user.first_name).to.equal('John'); + expect(persistedProducts[1].user.last_name).to.equal('Johnson'); }); it('should bulkCreate data for BelongsTo relations with no nullable FK', async function () { @@ -101,12 +101,12 @@ describe(Support.getTestDialectTeaser('Model'), () => { const savedProducts = await Product.bulkCreate([{ title: 'Chair', - User: { + user: { first_name: 'Mick', }, }, { title: 'Table', - User: { + user: { first_name: 'John', }, }], { @@ -117,13 +117,13 @@ describe(Support.getTestDialectTeaser('Model'), () => { expect(savedProducts[0]).to.exist; expect(savedProducts[0].title).to.equal('Chair'); - expect(savedProducts[0].User).to.exist; - expect(savedProducts[0].User.first_name).to.equal('Mick'); + expect(savedProducts[0].user).to.exist; + expect(savedProducts[0].user.first_name).to.equal('Mick'); expect(savedProducts[1]).to.exist; expect(savedProducts[1].title).to.equal('Table'); - expect(savedProducts[1].User).to.exist; - expect(savedProducts[1].User.first_name).to.equal('John'); + expect(savedProducts[1].user).to.exist; + expect(savedProducts[1].user.first_name).to.equal('John'); }); it('should bulkCreate data for BelongsTo relations with alias', async function () { @@ -182,8 +182,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { hooks: { afterBulkCreate(products) { for (const product of products) { - product.areIncludesCreatedOnAfterCreate = product.Tags - && product.Tags.every(tag => { + product.areIncludesCreatedOnAfterCreate = product.tags + && product.tags.every(tag => { return Boolean(tag.id); }); } @@ -209,14 +209,14 @@ describe(Support.getTestDialectTeaser('Model'), () => { const savedProducts = await Product.bulkCreate([{ id: 1, title: 'Chair', - Tags: [ + tags: [ { id: 1, name: 'Alpha' }, { id: 2, name: 'Beta' }, ], }, { id: 2, title: 'Table', - Tags: [ + tags: [ { id: 3, name: 'Gamma' }, { id: 4, name: 'Delta' }, ], @@ -228,12 +228,12 @@ describe(Support.getTestDialectTeaser('Model'), () => { }); expect(savedProducts[0].areIncludesCreatedOnAfterCreate).to.be.true; - expect(savedProducts[0].Tags[0].createOptions.myOption).to.equal('option'); - expect(savedProducts[0].Tags[1].createOptions.myOption).to.equal('option'); + expect(savedProducts[0].tags[0].createOptions.myOption).to.equal('option'); + expect(savedProducts[0].tags[1].createOptions.myOption).to.equal('option'); expect(savedProducts[1].areIncludesCreatedOnAfterCreate).to.be.true; - expect(savedProducts[1].Tags[0].createOptions.myOption).to.equal('option'); - expect(savedProducts[1].Tags[1].createOptions.myOption).to.equal('option'); + expect(savedProducts[1].tags[0].createOptions.myOption).to.equal('option'); + expect(savedProducts[1].tags[1].createOptions.myOption).to.equal('option'); const persistedProducts = await Promise.all([ Product.findOne({ @@ -246,11 +246,11 @@ describe(Support.getTestDialectTeaser('Model'), () => { }), ]); - expect(persistedProducts[0].Tags).to.be.ok; - expect(persistedProducts[0].Tags.length).to.equal(2); + expect(persistedProducts[0].tags).to.be.ok; + expect(persistedProducts[0].tags.length).to.equal(2); - expect(persistedProducts[1].Tags).to.be.ok; - expect(persistedProducts[1].Tags.length).to.equal(2); + expect(persistedProducts[1].tags).to.be.ok; + expect(persistedProducts[1].tags.length).to.equal(2); }); it('should bulkCreate data for HasMany relations with alias', async function () { @@ -316,12 +316,12 @@ describe(Support.getTestDialectTeaser('Model'), () => { const savedUsers = await User.bulkCreate([{ username: 'Muzzy', - Task: { + task: { title: 'Eat Clocks', }, }, { username: 'Walker', - Task: { + task: { title: 'Walk', }, }], { @@ -339,8 +339,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { }), ]); - expect(persistedUsers[0].Task).to.be.ok; - expect(persistedUsers[1].Task).to.be.ok; + expect(persistedUsers[0].task).to.be.ok; + expect(persistedUsers[1].task).to.be.ok; }); it('should bulkCreate data for HasOne relations with alias', async function () { @@ -392,8 +392,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { hooks: { afterBulkCreate(users) { for (const user of users) { - user.areIncludesCreatedOnAfterCreate = user.Tasks - && user.Tasks.every(task => { + user.areIncludesCreatedOnAfterCreate = user.tasks + && user.tasks.every(task => { return Boolean(task.id); }); } @@ -421,13 +421,13 @@ describe(Support.getTestDialectTeaser('Model'), () => { const savedUsers = await User.bulkCreate([{ username: 'John', - Tasks: [ + tasks: [ { title: 'Get rich', active: true }, { title: 'Die trying', active: false }, ], }, { username: 'Jack', - Tasks: [ + tasks: [ { title: 'Prepare sandwich', active: true }, { title: 'Each sandwich', active: false }, ], @@ -439,12 +439,12 @@ describe(Support.getTestDialectTeaser('Model'), () => { }); expect(savedUsers[0].areIncludesCreatedOnAfterCreate).to.be.true; - expect(savedUsers[0].Tasks[0].createOptions.myOption).to.equal('option'); - expect(savedUsers[0].Tasks[1].createOptions.myOption).to.equal('option'); + expect(savedUsers[0].tasks[0].createOptions.myOption).to.equal('option'); + expect(savedUsers[0].tasks[1].createOptions.myOption).to.equal('option'); expect(savedUsers[1].areIncludesCreatedOnAfterCreate).to.be.true; - expect(savedUsers[1].Tasks[0].createOptions.myOption).to.equal('option'); - expect(savedUsers[1].Tasks[1].createOptions.myOption).to.equal('option'); + expect(savedUsers[1].tasks[0].createOptions.myOption).to.equal('option'); + expect(savedUsers[1].tasks[1].createOptions.myOption).to.equal('option'); const persistedUsers = await Promise.all([ User.findOne({ @@ -457,11 +457,11 @@ describe(Support.getTestDialectTeaser('Model'), () => { }), ]); - expect(persistedUsers[0].Tasks).to.be.ok; - expect(persistedUsers[0].Tasks.length).to.equal(2); + expect(persistedUsers[0].tasks).to.be.ok; + expect(persistedUsers[0].tasks.length).to.equal(2); - expect(persistedUsers[1].Tasks).to.be.ok; - expect(persistedUsers[1].Tasks.length).to.equal(2); + expect(persistedUsers[1].tasks).to.be.ok; + expect(persistedUsers[1].tasks.length).to.equal(2); }); it('should bulkCreate data for polymorphic BelongsToMany relations', async function () { diff --git a/packages/core/test/integration/model/count.test.js b/packages/core/test/integration/model/count.test.js index 001eeb5f3b85..f904b93cdbeb 100644 --- a/packages/core/test/integration/model/count.test.js +++ b/packages/core/test/integration/model/count.test.js @@ -136,7 +136,7 @@ describe('Model.count', () => { await Post.sync({ force: true }); await PostComment.sync({ force: true }); const post = await Post.create({}); - await PostComment.bulkCreate([{ PostId: post.id }, { PostId: post.id }]); + await PostComment.bulkCreate([{ postId: post.id }, { postId: post.id }]); const count1 = await Post.count({ distinct: false, include: { model: PostComment, required: false } }); const count2 = await Post.count({ distinct: true, include: { model: PostComment, required: false } }); expect(count1).to.equal(2); @@ -256,7 +256,7 @@ describe('Model.count', () => { col: 'username', include: [this.Project], where: { - '$Projects.name$': 'project1', + '$projects.name$': 'project1', }, }; @@ -269,7 +269,7 @@ describe('Model.count', () => { await user.createProject({ name: 'project1' }); const count0 = await this.User.count(countOptions); expect(count0).to.be.eql(1); - countOptions.where['$Projects.name$'] = 'project2'; + countOptions.where['$projects.name$'] = 'project2'; const count = await this.User.count(countOptions); expect(count).to.be.eql(0); }); diff --git a/packages/core/test/integration/model/create/include.test.js b/packages/core/test/integration/model/create/include.test.js index 0cbe7f840fe2..16f1575d1f71 100644 --- a/packages/core/test/integration/model/create/include.test.js +++ b/packages/core/test/integration/model/create/include.test.js @@ -15,7 +15,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { }, { hooks: { afterCreate(product) { - product.isIncludeCreatedOnAfterCreate = Boolean(product.User && product.User.id); + product.isIncludeCreatedOnAfterCreate = Boolean(product.user && product.user.id); }, }, }); @@ -36,7 +36,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { const savedProduct = await Product.create({ title: 'Chair', - User: { + user: { first_name: 'Mick', last_name: 'Broadstone', }, @@ -48,17 +48,17 @@ describe(Support.getTestDialectTeaser('Model'), () => { }); expect(savedProduct.isIncludeCreatedOnAfterCreate).to.be.true; - expect(savedProduct.User.createOptions.myOption).to.equal('option'); - expect(savedProduct.User.createOptions.parentRecord).to.equal(savedProduct); + expect(savedProduct.user.createOptions.myOption).to.equal('option'); + expect(savedProduct.user.createOptions.parentRecord).to.equal(savedProduct); const persistedProduct = await Product.findOne({ where: { id: savedProduct.id }, include: [User], }); - expect(persistedProduct.User).to.be.ok; - expect(persistedProduct.User.first_name).to.equal('Mick'); - expect(persistedProduct.User.last_name).to.equal('Broadstone'); + expect(persistedProduct.user).to.be.ok; + expect(persistedProduct.user.first_name).to.equal('Mick'); + expect(persistedProduct.user.last_name).to.equal('Broadstone'); }); it('should create data for BelongsTo relations with no nullable FK', async function () { @@ -79,7 +79,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { const savedProduct = await Product.create({ title: 'Chair', - User: { + user: { first_name: 'Mick', }, }, { @@ -90,8 +90,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { expect(savedProduct).to.exist; expect(savedProduct.title).to.equal('Chair'); - expect(savedProduct.User).to.exist; - expect(savedProduct.User.first_name).to.equal('Mick'); + expect(savedProduct.user).to.exist; + expect(savedProduct.user.first_name).to.equal('Mick'); }); it('should create data for BelongsTo relations with alias', async function () { @@ -133,8 +133,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { }, { hooks: { afterCreate(product) { - product.areIncludesCreatedOnAfterCreate = product.Tags - && product.Tags.every(tag => { + product.areIncludesCreatedOnAfterCreate = product.tags + && product.tags.every(tag => { return Boolean(tag.id); }); }, @@ -157,7 +157,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { const savedProduct = await Product.create({ id: 1, title: 'Chair', - Tags: [ + tags: [ { id: 1, name: 'Alpha' }, { id: 2, name: 'Beta' }, ], @@ -169,18 +169,18 @@ describe(Support.getTestDialectTeaser('Model'), () => { }); expect(savedProduct.areIncludesCreatedOnAfterCreate).to.be.true; - expect(savedProduct.Tags[0].createOptions.myOption).to.equal('option'); - expect(savedProduct.Tags[0].createOptions.parentRecord).to.equal(savedProduct); - expect(savedProduct.Tags[1].createOptions.myOption).to.equal('option'); - expect(savedProduct.Tags[1].createOptions.parentRecord).to.equal(savedProduct); + expect(savedProduct.tags[0].createOptions.myOption).to.equal('option'); + expect(savedProduct.tags[0].createOptions.parentRecord).to.equal(savedProduct); + expect(savedProduct.tags[1].createOptions.myOption).to.equal('option'); + expect(savedProduct.tags[1].createOptions.parentRecord).to.equal(savedProduct); const persistedProduct = await Product.findOne({ where: { id: savedProduct.id }, include: [Tag], }); - expect(persistedProduct.Tags).to.be.ok; - expect(persistedProduct.Tags.length).to.equal(2); + expect(persistedProduct.tags).to.be.ok; + expect(persistedProduct.tags.length).to.equal(2); }); it('should create data for HasMany relations with alias', async function () { @@ -230,7 +230,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { const savedUser = await User.create({ username: 'Muzzy', - Task: { + task: { title: 'Eat Clocks', }, }, { @@ -242,7 +242,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { include: [Task], }); - expect(persistedUser.Task).to.be.ok; + expect(persistedUser.task).to.be.ok; }); it('should create data for HasOne relations with alias', async function () { @@ -281,8 +281,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { }, { hooks: { afterCreate(user) { - user.areIncludesCreatedOnAfterCreate = user.Tasks - && user.Tasks.every(task => { + user.areIncludesCreatedOnAfterCreate = user.tasks + && user.tasks.every(task => { return Boolean(task.id); }); }, @@ -307,7 +307,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { const savedUser = await User.create({ username: 'John', - Tasks: [ + tasks: [ { title: 'Get rich', active: true }, { title: 'Die trying', active: false }, ], @@ -319,18 +319,18 @@ describe(Support.getTestDialectTeaser('Model'), () => { }); expect(savedUser.areIncludesCreatedOnAfterCreate).to.be.true; - expect(savedUser.Tasks[0].createOptions.myOption).to.equal('option'); - expect(savedUser.Tasks[0].createOptions.parentRecord).to.equal(savedUser); - expect(savedUser.Tasks[1].createOptions.myOption).to.equal('option'); - expect(savedUser.Tasks[1].createOptions.parentRecord).to.equal(savedUser); + expect(savedUser.tasks[0].createOptions.myOption).to.equal('option'); + expect(savedUser.tasks[0].createOptions.parentRecord).to.equal(savedUser); + expect(savedUser.tasks[1].createOptions.myOption).to.equal('option'); + expect(savedUser.tasks[1].createOptions.parentRecord).to.equal(savedUser); const persistedUser = await User.findOne({ where: { id: savedUser.id }, include: [Task], }); - expect(persistedUser.Tasks).to.be.ok; - expect(persistedUser.Tasks.length).to.equal(2); + expect(persistedUser.tasks).to.be.ok; + expect(persistedUser.tasks.length).to.equal(2); }); it('should create data for polymorphic BelongsToMany relations', async function () { diff --git a/packages/core/test/integration/model/findAll.test.js b/packages/core/test/integration/model/findAll.test.js index 6d41131020d2..95010e58081d 100644 --- a/packages/core/test/integration/model/findAll.test.js +++ b/packages/core/test/integration/model/findAll.test.js @@ -583,8 +583,8 @@ Got { association: 1 } instead`); }); expect(tasks).to.exist; - expect(tasks[0].Worker).to.exist; - expect(tasks[0].Worker.name).to.equal('worker'); + expect(tasks[0].worker).to.exist; + expect(tasks[0].worker.name).to.equal('worker'); }); it('returns the associated worker via task.worker, using limit and sort', async function () { @@ -596,8 +596,8 @@ Got { association: 1 } instead`); }); expect(tasks).to.exist; - expect(tasks[0].Worker).to.exist; - expect(tasks[0].Worker.name).to.equal('worker'); + expect(tasks[0].worker).to.exist; + expect(tasks[0].worker.name).to.equal('worker'); }); }); @@ -629,8 +629,8 @@ Got { association: 1 } instead`); }); expect(workers).to.exist; - expect(workers[0].TaskHasOne).to.exist; - expect(workers[0].TaskHasOne.title).to.equal('homework'); + expect(workers[0].taskHasOne).to.exist; + expect(workers[0].taskHasOne.title).to.equal('homework'); }); }); @@ -1034,8 +1034,8 @@ The following associations are defined on "Worker": "ToDos"`); expect(kingdoms.length).to.be.eql(2); for (const kingdom of kingdoms) { - expect(kingdom.Animals).to.exist; // include model exists - expect(kingdom.Animals[0].AnimalKingdom).to.not.exist; // through doesn't exists + expect(kingdom.animals).to.exist; // include model exists + expect(kingdom.animals[0].AnimalKingdom).to.not.exist; // through doesn't exists } }); @@ -1422,7 +1422,7 @@ The following associations are defined on "Worker": "ToDos"`); await User.create({ name: 'some user', - Image: { + image: { path: 'folder1/folder2/logo.png', }, }, { @@ -1441,8 +1441,8 @@ The following associations are defined on "Worker": "ToDos"`); for (const user of users) { expect(user.get('name')).to.equal('some user'); - expect(user.Image.get('url')).to.equal('https://my-cool-domain.com/folder1/folder2/logo.png'); - expect(user.Image.get('path')).to.equal('folder1/folder2/logo.png'); + expect(user.image.get('url')).to.equal('https://my-cool-domain.com/folder1/folder2/logo.png'); + expect(user.image.get('path')).to.equal('folder1/folder2/logo.png'); } }); }); @@ -1539,7 +1539,7 @@ The following associations are defined on "Worker": "ToDos"`); name: 'Some election', }, include: [ - 'Citizen', // Election creator + 'citizen', // Election creator { model: Citizen, as: 'Voters' }, // Election voters ], }); diff --git a/packages/core/test/integration/model/findAll/group.test.js b/packages/core/test/integration/model/findAll/group.test.js index a034e44584e9..c29125e841bd 100644 --- a/packages/core/test/integration/model/findAll/group.test.js +++ b/packages/core/test/integration/model/findAll/group.test.js @@ -34,15 +34,15 @@ describe(Support.getTestDialectTeaser('Model'), () => { ]); await Comment.bulkCreate([ - { text: 'Market', PostId: 1 }, - { text: 'Text', PostId: 2 }, - { text: 'Abc', PostId: 2 }, - { text: 'Semaphor', PostId: 1 }, - { text: 'Text', PostId: 1 }, + { text: 'Market', postId: 1 }, + { text: 'Text', postId: 2 }, + { text: 'Abc', postId: 2 }, + { text: 'Semaphor', postId: 1 }, + { text: 'Text', postId: 1 }, ]); const posts = await Post.findAll({ - attributes: [[Sequelize.fn('COUNT', Sequelize.col('Comments.id')), 'comment_count']], + attributes: [[Sequelize.fn('COUNT', Sequelize.col('comments.id')), 'comment_count']], include: [ { model: Comment, attributes: [] }, ], @@ -78,21 +78,21 @@ describe(Support.getTestDialectTeaser('Model'), () => { ]); await Comment.bulkCreate([ - { text: 'Market', PostId: 1 }, - { text: 'Text', PostId: 2 }, - { text: 'Abc', PostId: 2 }, - { text: 'Semaphor', PostId: 1 }, - { text: 'Text', PostId: 1 }, + { text: 'Market', postId: 1 }, + { text: 'Text', postId: 2 }, + { text: 'Abc', postId: 2 }, + { text: 'Semaphor', postId: 1 }, + { text: 'Text', postId: 1 }, ]); const posts = await Comment.findAll({ - attributes: ['PostId', [Sequelize.fn('COUNT', Sequelize.col('Comment.id')), 'comment_count']], + attributes: ['postId', [Sequelize.fn('COUNT', Sequelize.col('Comment.id')), 'comment_count']], include: [ { model: Post, attributes: [] }, ], - group: ['PostId'], + group: ['postId'], order: [ - ['PostId'], + ['postId'], ], }); diff --git a/packages/core/test/integration/model/findAll/separate.test.js b/packages/core/test/integration/model/findAll/separate.test.js index 8b963520d629..0e6d8a046bd8 100644 --- a/packages/core/test/integration/model/findAll/separate.test.js +++ b/packages/core/test/integration/model/findAll/separate.test.js @@ -24,84 +24,76 @@ describe(Support.getTestDialectTeaser('Model'), () => { LevelTwo.hasMany(LevelThree, { as: 'type_twos' }); LevelThree.belongsTo(LevelTwo); - try { - try { - await current.sync({ force: true }); + await current.sync({ force: true }); - const [project, level21, level22] = await Promise.all([ - Project.create({ name: 'testProject' }), - LevelTwo.create({ name: 'testL21' }), - LevelTwo.create({ name: 'testL22' }), - ]); + const [project, level21, level22] = await Promise.all([ + Project.create({ name: 'testProject' }), + LevelTwo.create({ name: 'testL21' }), + LevelTwo.create({ name: 'testL22' }), + ]); - await Promise.all([ - project.addLevelTwo(level21), - project.addLevelTwo(level22), - ]); + await Promise.all([ + project.addLevelTwo(level21), + project.addLevelTwo(level22), + ]); - // one include case - const projects0 = await Project.findAll({ - where: { name: 'testProject' }, + // one include case + const projects0 = await Project.findAll({ + where: { name: 'testProject' }, + include: [ + { + model: LevelTwo, include: [ { - model: LevelTwo, - include: [ - { - model: LevelThree, - as: 'type_ones', - where: { type: 0 }, - separate: true, - limit: 1, - order: [['createdAt', 'DESC']], - }, - ], + model: LevelThree, + as: 'type_ones', + where: { type: 0 }, + separate: true, + limit: 1, + order: [['createdAt', 'DESC']], }, ], - }); + }, + ], + }); - expect(projects0).to.have.length(1); - expect(projects0[0].LevelTwos).to.have.length(2); - expect(projects0[0].LevelTwos[0].type_ones).to.have.length(0); - expect(projects0[0].LevelTwos[1].type_ones).to.have.length(0); - } catch { - expect.fail(); - } + expect(projects0).to.have.length(1); + expect(projects0[0].levelTwos).to.have.length(2); + expect(projects0[0].levelTwos[0].type_ones).to.have.length(0); + expect(projects0[0].levelTwos[1].type_ones).to.have.length(0); - // two includes case - const projects = await Project.findAll({ - where: { name: 'testProject' }, - include: [ - { - model: LevelTwo, - include: [ - { - model: LevelThree, - as: 'type_ones', - where: { type: 0 }, - separate: true, - limit: 1, - order: [['createdAt', 'DESC']], - }, - { - model: LevelThree, - as: 'type_twos', - where: { type: 1 }, - separate: true, - limit: 1, - order: [['createdAt', 'DESC']], - }, - ], - }, - ], - }); + // two includes case + const projects = await Project.findAll({ + where: { name: 'testProject' }, + include: [ + { + model: LevelTwo, + include: [ + { + model: LevelThree, + as: 'type_ones', + where: { type: 0 }, + separate: true, + limit: 1, + order: [['createdAt', 'DESC']], + }, + { + model: LevelThree, + as: 'type_twos', + where: { type: 1 }, + separate: true, + limit: 1, + order: [['createdAt', 'DESC']], + }, + ], + }, + ], + }); - expect(projects).to.have.length(1); - expect(projects[0].LevelTwos).to.have.length(2); - expect(projects[0].LevelTwos[0].type_ones).to.have.length(0); - expect(projects[0].LevelTwos[1].type_ones).to.have.length(0); - } catch { - expect.fail(); - } + expect(projects).to.have.length(1); + expect(projects[0].levelTwos).to.have.length(2); + expect(projects[0].levelTwos[0].type_ones).to.have.length(0); + expect(projects[0].levelTwos[1].type_ones).to.have.length(0); }); }); }); diff --git a/packages/core/test/integration/model/findOne.test.js b/packages/core/test/integration/model/findOne.test.js index bd94cd9d4437..7d8b8157d421 100644 --- a/packages/core/test/integration/model/findOne.test.js +++ b/packages/core/test/integration/model/findOne.test.js @@ -464,8 +464,8 @@ Got { association: 1 } instead`); }); expect(task).to.exist; - expect(task.Worker).to.exist; - expect(task.Worker.name).to.equal('worker'); + expect(task.worker).to.exist; + expect(task.worker.name).to.equal('worker'); }); }); }); @@ -517,7 +517,7 @@ Got { association: 1 } instead`); await this.sequelize.sync({ force: true }); await this.Group.create({ name: 'people' }); - await this.User.create({ username: 'someone', GroupPKeagerbelongName: 'people' }); + await this.User.create({ username: 'someone', groupPKeagerbelongName: 'people' }); const someUser = await this.User.findOne({ where: { @@ -528,7 +528,7 @@ Got { association: 1 } instead`); expect(someUser).to.exist; expect(someUser.username).to.equal('someone'); - expect(someUser.GroupPKeagerbelong.name).to.equal('people'); + expect(someUser.groupPKeagerbelong.name).to.equal('people'); }); it('getting parent data in many to one relationship', async function () { @@ -562,10 +562,10 @@ Got { association: 1 } instead`); expect(messages.length).to.equal(2); expect(messages[0].message).to.equal('hi there!'); - expect(messages[0].User.username).to.equal('test_testerson'); + expect(messages[0].user.username).to.equal('test_testerson'); expect(messages[1].message).to.equal('a second message'); - expect(messages[1].User.username).to.equal('test_testerson'); + expect(messages[1].user.username).to.equal('test_testerson'); }); it('allows mulitple assocations of the same model with different alias', async function () { @@ -607,8 +607,8 @@ Got { association: 1 } instead`); }); expect(worker).to.exist; - expect(worker.Task).to.exist; - expect(worker.Task.title).to.equal('homework'); + expect(worker.task).to.exist; + expect(worker.task.title).to.equal('homework'); }); it('eager loads with non-id primary keys', async function () { @@ -628,7 +628,7 @@ Got { association: 1 } instead`); await this.sequelize.sync({ force: true }); await this.Group.create({ name: 'people' }); - await this.User.create({ username: 'someone', GroupPKeageroneName: 'people' }); + await this.User.create({ username: 'someone', groupPKeageroneName: 'people' }); const someGroup = await this.Group.findOne({ where: { @@ -639,7 +639,7 @@ Got { association: 1 } instead`); expect(someGroup).to.exist; expect(someGroup.name).to.equal('people'); - expect(someGroup.UserPKeagerone.username).to.equal('someone'); + expect(someGroup.userPKeagerone.username).to.equal('someone'); }); }); @@ -729,8 +729,8 @@ The following associations are defined on "Worker": "ToDo"`); }); expect(worker).to.exist; - expect(worker.Tasks).to.exist; - expect(worker.Tasks[0].title).to.equal('homework'); + expect(worker.tasks).to.exist; + expect(worker.tasks[0].title).to.equal('homework'); }); it('including two has many relations should not result in duplicate values', async function () { @@ -758,7 +758,7 @@ The following associations are defined on "Worker": "ToDo"`); expect(fetchedContact).to.exist; expect(fetchedContact.Photos.length).to.equal(1); - expect(fetchedContact.PhoneNumbers.length).to.equal(2); + expect(fetchedContact.phoneNumbers.length).to.equal(2); }); it('eager loads with non-id primary keys', async function () { @@ -791,7 +791,7 @@ The following associations are defined on "Worker": "ToDo"`); expect(someUser0).to.exist; expect(someUser0.username).to.equal('someone'); - expect(someUser0.GroupPKeagerones[0].name).to.equal('people'); + expect(someUser0.groupPKeagerones[0].name).to.equal('people'); }); }); diff --git a/packages/core/test/integration/model/findOrBuild.test.js b/packages/core/test/integration/model/findOrBuild.test.js index 188ea5d4a9f7..5a2086322576 100644 --- a/packages/core/test/integration/model/findOrBuild.test.js +++ b/packages/core/test/integration/model/findOrBuild.test.js @@ -91,8 +91,8 @@ describe('Model#findOrBuild', () => { expect(user.get('username')).to.equal('Mello'); expect(user.get('age')).to.equal(20); - expect(user.Projects).to.have.length(1); - expect(user.Projects[0].get('name')).to.equal('Investigate'); + expect(user.projects).to.have.length(1); + expect(user.projects[0].get('name')).to.equal('Investigate'); }); }); diff --git a/packages/core/test/integration/model/paranoid.test.js b/packages/core/test/integration/model/paranoid.test.js index 897edd97b69f..566b1908a683 100644 --- a/packages/core/test/integration/model/paranoid.test.js +++ b/packages/core/test/integration/model/paranoid.test.js @@ -189,7 +189,7 @@ describe('Paranoid Model', () => { }, { paranoid: true }); const Pet = this.sequelize.define('Pet', { name: DataTypes.STRING, - UserId: DataTypes.INTEGER, + userId: DataTypes.INTEGER, }, { paranoid: true }); User.hasMany(Pet); @@ -199,8 +199,8 @@ describe('Paranoid Model', () => { await Pet.sync({ force: true }); const userId = (await User.create({ username: 'Joe' })).id; await Pet.bulkCreate([ - { name: 'Fido', UserId: userId }, - { name: 'Fifi', UserId: userId }, + { name: 'Fido', userId }, + { name: 'Fifi', userId }, ]); const pet = await Pet.findByPk(1); await pet.destroy(); @@ -213,8 +213,8 @@ describe('Paranoid Model', () => { include: { model: Pet, paranoid: false }, }); expect(user).to.exist; - expect(user.Pets).to.have.length(1); + expect(user.pets).to.have.length(1); expect(userWithDeletedPets).to.exist; - expect(userWithDeletedPets.Pets).to.have.length(2); + expect(userWithDeletedPets.pets).to.have.length(2); }); }); diff --git a/packages/core/test/integration/model/scope/associations.test.js b/packages/core/test/integration/model/scope/associations.test.js index 98e8ab673579..6d5e162b7b7c 100644 --- a/packages/core/test/integration/model/scope/associations.test.js +++ b/packages/core/test/integration/model/scope/associations.test.js @@ -340,8 +340,8 @@ describe(Support.getTestDialectTeaser('Model'), () => { }); expect(parent.get('name')).to.equal('parent2'); - expect(parent.Children).to.have.length(1); - expect(parent.Children[0].dataValues).not.to.have.property('name'); + expect(parent.children).to.have.length(1); + expect(parent.children[0].dataValues).not.to.have.property('name'); }); }); }); @@ -366,7 +366,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { await this.sequelize.sync({ force: true }); await Child.create({ secret: 'super secret' }); const user = await Child.scope('public').findOne(); - expect(user.dataValues).to.have.property('ParentId'); + expect(user.dataValues).to.have.property('parentId'); expect(user.dataValues).not.to.have.property('secret'); }); @@ -386,7 +386,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { await this.sequelize.sync({ force: true }); await Child.create({ secret: 'super secret' }); const user = await Child.findOne(); - expect(user.dataValues).to.have.property('ParentId'); + expect(user.dataValues).to.have.property('parentId'); expect(user.dataValues).not.to.have.property('secret'); }); diff --git a/packages/core/test/integration/model/scope/count.test.js b/packages/core/test/integration/model/scope/count.test.js index 0ae424cb9e44..485d7cf7c296 100644 --- a/packages/core/test/integration/model/scope/count.test.js +++ b/packages/core/test/integration/model/scope/count.test.js @@ -63,7 +63,7 @@ describe(Support.getTestDialectTeaser('Model'), () => { withIncludeFunctionAndStringAssociation: () => { return { include: [{ - association: 'Children', + association: 'children', where: { priority: 1, }, diff --git a/packages/core/test/integration/model/sync.test.js b/packages/core/test/integration/model/sync.test.js index 79dd18e2e23b..f77c2f3e4ef7 100644 --- a/packages/core/test/integration/model/sync.test.js +++ b/packages/core/test/integration/model/sync.test.js @@ -546,12 +546,12 @@ describe(getTestDialectTeaser('Model.sync & Sequelize#sync'), () => { expect(aFks.length).to.eq(1); expect(aFks[0].referencedTableName).to.eq('Bs'); expect(aFks[0].referencedColumnNames).to.deep.eq(['id']); - expect(aFks[0].columnNames).to.deep.eq(['BId']); + expect(aFks[0].columnNames).to.deep.eq(['bId']); expect(bFks.length).to.eq(1); expect(bFks[0].referencedTableName).to.eq('As'); expect(bFks[0].referencedColumnNames).to.deep.eq(['id']); - expect(bFks[0].columnNames).to.deep.eq(['AId']); + expect(bFks[0].columnNames).to.deep.eq(['aId']); }); // TODO: sqlite's foreign_key_list pragma does not return the DEFERRABLE status of the column @@ -578,7 +578,7 @@ describe(getTestDialectTeaser('Model.sync & Sequelize#sync'), () => { expect(aFks).to.have.length(1); expect(aFks[0].deferrable).to.eq(Deferrable.INITIALLY_IMMEDIATE); - A.modelDefinition.rawAttributes.BId.references.deferrable = Deferrable.INITIALLY_DEFERRED; + A.modelDefinition.rawAttributes.bId.references.deferrable = Deferrable.INITIALLY_DEFERRED; A.modelDefinition.refreshAttributes(); await sequelize.sync({ alter: true }); diff --git a/packages/core/test/integration/query-interface/changeColumn.test.js b/packages/core/test/integration/query-interface/changeColumn.test.js index 3cc93c1ee55b..e6da5ec357ca 100644 --- a/packages/core/test/integration/query-interface/changeColumn.test.js +++ b/packages/core/test/integration/query-interface/changeColumn.test.js @@ -351,21 +351,21 @@ describe(Support.getTestDialectTeaser('QueryInterface'), () => { await this.queryInterface.addColumn('Tasks', 'bar', DataTypes.INTEGER); let refs = await this.queryInterface.showConstraints(Task, { constraintType: 'FOREIGN KEY' }); expect(refs.length).to.equal(1, 'should keep foreign key after adding column'); - expect(refs[0].columnNames).to.deep.equal(['UserId']); + expect(refs[0].columnNames).to.deep.equal(['userId']); expect(refs[0].referencedTableName).to.equal('Users'); expect(refs[0].referencedColumnNames).to.deep.equal(['id']); await this.queryInterface.changeColumn('Tasks', 'bar', DataTypes.STRING); refs = await this.queryInterface.showConstraints(Task, { constraintType: 'FOREIGN KEY' }); expect(refs.length).to.equal(1, 'should keep foreign key after changing column'); - expect(refs[0].columnNames).to.deep.equal(['UserId']); + expect(refs[0].columnNames).to.deep.equal(['userId']); expect(refs[0].referencedTableName).to.equal('Users'); expect(refs[0].referencedColumnNames).to.deep.equal(['id']); await this.queryInterface.renameColumn('Tasks', 'bar', 'foo'); refs = await this.queryInterface.showConstraints(Task, { constraintType: 'FOREIGN KEY' }); expect(refs.length).to.equal(1, 'should keep foreign key after renaming column'); - expect(refs[0].columnNames).to.deep.equal(['UserId']); + expect(refs[0].columnNames).to.deep.equal(['userId']); expect(refs[0].referencedTableName).to.equal('Users'); expect(refs[0].referencedColumnNames).to.deep.equal(['id']); }); diff --git a/packages/core/test/integration/sequelize/drop.test.ts b/packages/core/test/integration/sequelize/drop.test.ts index 7a4887885654..1c1bb4c8be4f 100644 --- a/packages/core/test/integration/sequelize/drop.test.ts +++ b/packages/core/test/integration/sequelize/drop.test.ts @@ -7,7 +7,7 @@ const dialect = sequelize.getDialect(); describe('Sequelize#drop', () => { it('supports dropping cyclic associations', async () => { const A = sequelize.define('A', { - BId: { + bId: { type: DataTypes.INTEGER, references: { deferrable: Deferrable.INITIALLY_IMMEDIATE, @@ -16,7 +16,7 @@ describe('Sequelize#drop', () => { }); const B = sequelize.define('B', { - AId: { + aId: { type: DataTypes.INTEGER, references: { deferrable: Deferrable.INITIALLY_IMMEDIATE, @@ -44,13 +44,13 @@ describe('Sequelize#drop', () => { } const A = sequelize.define('A', { - BId: { + bId: { type: DataTypes.INTEGER, }, }); const B = sequelize.define('B', { - AId: { + aId: { type: DataTypes.INTEGER, }, }); diff --git a/packages/core/test/integration/sequelize/truncate.test.ts b/packages/core/test/integration/sequelize/truncate.test.ts index f37164ee038e..ac1cf5b2651d 100644 --- a/packages/core/test/integration/sequelize/truncate.test.ts +++ b/packages/core/test/integration/sequelize/truncate.test.ts @@ -5,12 +5,12 @@ import { beforeAll2, sequelize, setResetMode } from '../support'; interface IA extends Model, InferCreationAttributes> { id: CreationOptional; - BId: number | null; + bId: number | null; } interface IB extends Model, InferCreationAttributes> { id: CreationOptional; - AId: number | null; + aId: number | null; } describe('Sequelize#truncate', () => { @@ -19,12 +19,12 @@ describe('Sequelize#truncate', () => { const vars = beforeAll2(async () => { const A = sequelize.define('A', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, - BId: { type: DataTypes.INTEGER }, + bId: { type: DataTypes.INTEGER }, }); const B = sequelize.define('B', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, - AId: { type: DataTypes.INTEGER }, + aId: { type: DataTypes.INTEGER }, }); // These models both have a foreign key that references the other model. @@ -43,14 +43,14 @@ describe('Sequelize#truncate', () => { await sequelize.transaction(async transaction => { const a = await A.create({ - BId: null, + bId: null, }, { transaction }); const b = await B.create({ - AId: a.id, + aId: a.id, }, { transaction }); - a.BId = b.id; + a.bId = b.id; await a.save({ transaction }); }); @@ -68,14 +68,14 @@ describe('Sequelize#truncate', () => { await sequelize.transaction(async transaction => { const a = await A.create({ - BId: null, + bId: null, }, { transaction }); const b = await B.create({ - AId: a.id, + aId: a.id, }, { transaction }); - a.BId = b.id; + a.bId = b.id; await a.save({ transaction }); }); diff --git a/packages/core/test/unit/associations/association.test.ts b/packages/core/test/unit/associations/association.test.ts index 853a6d5bd3bf..a17729a649b4 100644 --- a/packages/core/test/unit/associations/association.test.ts +++ b/packages/core/test/unit/associations/association.test.ts @@ -19,11 +19,11 @@ describe(getTestDialectTeaser('belongsTo'), () => { const Task = sequelize.define('Task'); const association = User.belongsTo(Task); - expect(association.as).to.eq('Task'); + expect(association.as).to.eq('task'); expect(() => { - User.belongsTo(Task, { as: 'Task' }); - }).to.throw(AssociationError, 'You have defined two associations with the same name "Task" on the model "User". Use another alias using the "as" parameter.'); + User.belongsTo(Task, { as: 'task' }); + }).to.throw(AssociationError, 'You have defined two associations with the same name "task" on the model "User". Use another alias using the "as" parameter.'); }); it('should throw an AssociationError when two associations have the same alias (both inferred)', () => { @@ -34,6 +34,6 @@ describe(getTestDialectTeaser('belongsTo'), () => { expect(() => { User.belongsTo(Task); - }).to.throw(AssociationError, 'You have defined two associations with the same name "Task" on the model "User". Use another alias using the "as" parameter.'); + }).to.throw(AssociationError, 'You have defined two associations with the same name "task" on the model "User". Use another alias using the "as" parameter.'); }); }); diff --git a/packages/core/test/unit/associations/belongs-to-many.test.ts b/packages/core/test/unit/associations/belongs-to-many.test.ts index ffc2974b4974..0d31b1b6a180 100644 --- a/packages/core/test/unit/associations/belongs-to-many.test.ts +++ b/packages/core/test/unit/associations/belongs-to-many.test.ts @@ -34,6 +34,16 @@ describe(getTestDialectTeaser('belongsToMany'), () => { }).to.throw(`User.belongsToMany was called with undefined as the target model, but it is not a subclass of Sequelize's Model class`); }); + it('creates the join table when through is a string', async () => { + const User = sequelize.define('User'); + const Group = sequelize.define('Group'); + + User.belongsToMany(Group, { as: 'MyGroups', through: 'GroupUser' }); + Group.belongsToMany(User, { as: 'MyUsers', through: 'GroupUser' }); + + expect(sequelize.model('GroupUser')).to.exist; + }); + it('should not inherit scopes from parent to join table', () => { const A = sequelize.define('a'); const B = sequelize.define('b', {}, { @@ -226,7 +236,17 @@ describe(getTestDialectTeaser('belongsToMany'), () => { expect(() => { Post.belongsToMany(User, { through: { model: 'UserPost' } }); - }).to.throw('You have defined two associations with the same name "Users" on the model "Post". Use another alias using the "as" parameter'); + }).to.throw('You have defined two associations with the same name "users" on the model "Post". Use another alias using the "as" parameter'); + }); + + it('generates a default association name', () => { + const User = sequelize.define('User', {}); + const Task = sequelize.define('Task', {}); + + User.belongsToMany(Task, { through: 'UserTask' }); + + expect(Object.keys(Task.associations)).to.deep.eq(['users', 'usersTasks', 'userTask']); + expect(Object.keys(User.associations)).to.deep.eq(['tasks', 'tasksUsers', 'taskUser']); }); describe('proper syntax', () => { @@ -378,7 +398,7 @@ describe(getTestDialectTeaser('belongsToMany'), () => { const Place = sequelize.define('Place', {}); const Places = User.belongsToMany(Place, { through: 'user_places', foreignKey: 'user_id', otherKey: 'place_id' }); - const Users = Place.getAssociation('Users') as BelongsToManyAssociation; + const Users = Place.getAssociation('users') as BelongsToManyAssociation; expect(Places.pairedWith).to.equal(Users); expect(Users.pairedWith).to.equal(Places); @@ -402,7 +422,7 @@ describe(getTestDialectTeaser('belongsToMany'), () => { }, { timestamps: false }); const Places = User.belongsToMany(Place, { through: UserPlace, foreignKey: 'user_id', otherKey: 'place_id' }); - const Users = Place.getAssociation('Users') as BelongsToManyAssociation; + const Users = Place.getAssociation('users') as BelongsToManyAssociation; expect(Places.pairedWith).to.equal(Users); expect(Users.pairedWith).to.equal(Places); @@ -421,8 +441,8 @@ describe(getTestDialectTeaser('belongsToMany'), () => { const PersonChildren = sequelize.define('PersonChildren'); const Children = Person.belongsToMany(Person, { as: 'Children', through: PersonChildren, inverse: { as: 'Parents' } }); - expect(Children.foreignKey).to.equal('ParentId'); - expect(Children.otherKey).to.equal('ChildId'); + expect(Children.foreignKey).to.equal('parentId'); + expect(Children.otherKey).to.equal('childId'); expect(PersonChildren.getAttributes()[Children.foreignKey]).to.be.ok; expect(PersonChildren.getAttributes()[Children.otherKey]).to.be.ok; }); @@ -432,12 +452,12 @@ describe(getTestDialectTeaser('belongsToMany'), () => { const PersonChildren = sequelize.define('PersonChildren', {}, { underscored: true }); const Children = Person.belongsToMany(Person, { as: 'Children', through: PersonChildren, inverse: { as: 'Parents' } }); - expect(Children.foreignKey).to.equal('ParentId'); - expect(Children.otherKey).to.equal('ChildId'); + expect(Children.foreignKey).to.equal('parentId'); + expect(Children.otherKey).to.equal('childId'); expect(PersonChildren.getAttributes()[Children.foreignKey]).to.be.ok; expect(PersonChildren.getAttributes()[Children.otherKey]).to.be.ok; - expect(PersonChildren.getAttributes()[Children.foreignKey].field).to.equal('parent_id'); - expect(PersonChildren.getAttributes()[Children.otherKey].field).to.equal('child_id'); + expect(PersonChildren.getAttributes()[Children.foreignKey].columnName).to.equal('parent_id'); + expect(PersonChildren.getAttributes()[Children.otherKey].columnName).to.equal('child_id'); }); it('should create non-null foreign keys by default', () => { @@ -447,8 +467,8 @@ describe(getTestDialectTeaser('belongsToMany'), () => { const association = A.belongsToMany(B, { through: 'AB' }); const attributes = association.throughModel.getAttributes(); - expect(attributes.AId.allowNull).to.be.false; - expect(attributes.BId.allowNull).to.be.false; + expect(attributes.aId.allowNull).to.be.false; + expect(attributes.bId.allowNull).to.be.false; }); it('allows creating nullable FKs', () => { @@ -462,8 +482,8 @@ describe(getTestDialectTeaser('belongsToMany'), () => { }); const attributes = association.throughModel.getAttributes(); - expect(attributes.AId.allowNull).to.be.true; - expect(attributes.BId.allowNull).to.be.true; + expect(attributes.aId.allowNull).to.be.true; + expect(attributes.bId.allowNull).to.be.true; }); it('should add FKs with onDelete=cascade by default', () => { @@ -473,8 +493,8 @@ describe(getTestDialectTeaser('belongsToMany'), () => { const association = A.belongsToMany(B, { through: 'AB', foreignKey: {} }); const attributes = association.throughModel.getAttributes(); - expect(attributes.AId.onDelete).to.eq('CASCADE'); - expect(attributes.BId.onDelete).to.eq('CASCADE'); + expect(attributes.aId.onDelete).to.eq('CASCADE'); + expect(attributes.bId.onDelete).to.eq('CASCADE'); }); }); @@ -484,7 +504,7 @@ describe(getTestDialectTeaser('belongsToMany'), () => { const Place = sequelize.define('Place', { place_id: DataTypes.UUID }); const Places = User.belongsToMany(Place, { through: 'user_places', sourceKey: 'user_id', targetKey: 'place_id' }); - const Users = Place.getAssociation('Users') as BelongsToManyAssociation; + const Users = Place.getAssociation('users') as BelongsToManyAssociation; expect(Places.pairedWith).to.equal(Users); expect(Users.pairedWith).to.equal(Places); @@ -508,7 +528,7 @@ describe(getTestDialectTeaser('belongsToMany'), () => { }, { timestamps: false }); const Places = User.belongsToMany(Place, { through: UserPlace, sourceKey: 'user_id', targetKey: 'place_id' }); - const Users = Place.getAssociation('Users') as BelongsToManyAssociation; + const Users = Place.getAssociation('users') as BelongsToManyAssociation; expect(Places.pairedWith).to.equal(Users); expect(Users.pairedWith).to.equal(Places); @@ -656,10 +676,10 @@ describe(getTestDialectTeaser('belongsToMany'), () => { }); const ProductTags = Product.belongsToMany(Tag, { through: ProductTag, sourceKey: 'productSecondaryId', targetKey: 'tagSecondaryId' }); - const TagProducts = Tag.getAssociation('Products') as BelongsToManyAssociation; + const TagProducts = Tag.getAssociation('products') as BelongsToManyAssociation; - expect(ProductTags.foreignKey).to.equal('ProductProductSecondaryId', 'generated foreign key for source name (product) + source key (productSecondaryId) should result in ProductProductSecondaryId'); - expect(TagProducts.foreignKey).to.equal('TagTagSecondaryId'); + expect(ProductTags.foreignKey).to.equal('productProductSecondaryId', 'generated foreign key for source name (product) + source key (productSecondaryId) should result in productProductSecondaryId'); + expect(TagProducts.foreignKey).to.equal('tagTagSecondaryId'); expect(ProductTags.fromSourceToThroughOne).to.be.an.instanceOf(HasOneAssociation); expect(ProductTags.fromTargetToThroughOne).to.be.an.instanceOf(HasOneAssociation); @@ -674,7 +694,7 @@ describe(getTestDialectTeaser('belongsToMany'), () => { expect(ProductTags.fromTargetToThroughOne.sourceKey).to.equal(ProductTags.targetKey); expect(Object.keys(ProductTag.getAttributes()).length).to.equal(4); - expect(Object.keys(ProductTag.getAttributes()).sort()).to.deep.equal(['id', 'priority', 'ProductProductSecondaryId', 'TagTagSecondaryId'].sort()); + expect(Object.keys(ProductTag.getAttributes()).sort()).to.deep.equal(['id', 'priority', 'productProductSecondaryId', 'tagTagSecondaryId'].sort()); }); it('should setup belongsTo relations to source and target from join model with only foreign keys defined', () => { @@ -696,7 +716,7 @@ describe(getTestDialectTeaser('belongsToMany'), () => { }); const ProductTags = Product.belongsToMany(Tag, { through: ProductTag, foreignKey: 'product_ID', otherKey: 'tag_ID' }); - const TagProducts = Tag.getAssociation('Products') as BelongsToManyAssociation; + const TagProducts = Tag.getAssociation('products') as BelongsToManyAssociation; expect(ProductTags.fromThroughToSource).to.be.ok; expect(ProductTags.fromThroughToTarget).to.be.ok; @@ -733,7 +753,7 @@ describe(getTestDialectTeaser('belongsToMany'), () => { }); const ProductTags = Product.belongsToMany(Tag, { through: ProductTag, foreignKey: 'product_ID', otherKey: 'tag_ID' }); - const TagProducts = Tag.getAssociation('Products') as BelongsToManyAssociation; + const TagProducts = Tag.getAssociation('products') as BelongsToManyAssociation; expect(ProductTags.fromSourceToThroughOne).to.be.an.instanceOf(HasOneAssociation); expect(ProductTags.fromTargetToThroughOne).to.be.an.instanceOf(HasOneAssociation); @@ -785,7 +805,7 @@ describe(getTestDialectTeaser('belongsToMany'), () => { expect(TagProducts.fromThroughToTarget.foreignKey).to.equal(TagProducts.otherKey); expect(Object.keys(ProductTag.getAttributes()).length).to.equal(4); - expect(Object.keys(ProductTag.getAttributes()).sort()).to.deep.equal(['id', 'priority', 'ProductId', 'TagId'].sort()); + expect(Object.keys(ProductTag.getAttributes()).sort()).to.deep.equal(['id', 'priority', 'productId', 'tagId'].sort()); }); }); @@ -859,8 +879,8 @@ describe(getTestDialectTeaser('belongsToMany'), () => { through: UserFollower, }); - expect(UserFollowers.foreignKey).to.eq('FollowingId'); - expect(UserFollowers.otherKey).to.eq('FollowerId'); + expect(UserFollowers.foreignKey).to.eq('followingId'); + expect(UserFollowers.otherKey).to.eq('followerId'); expect(Object.keys(UserFollower.getAttributes()).length).to.equal(3); }); @@ -916,13 +936,13 @@ describe(getTestDialectTeaser('belongsToMany'), () => { const throughModel = MyUsers.through.model; expect(Object.keys(throughModel.getAttributes()).sort()) - .to.deep.equal(['UserId', 'GroupId', 'createdAt', 'updatedAt'].sort()); + .to.deep.equal(['userId', 'groupId', 'createdAt', 'updatedAt'].sort()); expect(throughModel === MyGroups.through.model); - expect(throughModel.getAttributes().UserId.onUpdate).to.equal('RESTRICT'); - expect(throughModel.getAttributes().UserId.onDelete).to.equal('SET NULL'); - expect(throughModel.getAttributes().GroupId.onUpdate).to.equal('SET NULL'); - expect(throughModel.getAttributes().GroupId.onDelete).to.equal('RESTRICT'); + expect(throughModel.getAttributes().userId.onUpdate).to.equal('RESTRICT'); + expect(throughModel.getAttributes().userId.onDelete).to.equal('SET NULL'); + expect(throughModel.getAttributes().groupId.onUpdate).to.equal('SET NULL'); + expect(throughModel.getAttributes().groupId.onDelete).to.equal('RESTRICT'); }); it('work properly when through is a model', () => { @@ -954,12 +974,12 @@ describe(getTestDialectTeaser('belongsToMany'), () => { const Through = MyUsers.through.model; expect(Object.keys(Through.getAttributes()).sort()) - .to.deep.equal(['UserId', 'GroupId', 'createdAt', 'updatedAt'].sort()); + .to.deep.equal(['userId', 'groupId', 'createdAt', 'updatedAt'].sort()); - expect(Through.getAttributes().UserId.onUpdate).to.equal('RESTRICT', 'UserId.onUpdate should have been RESTRICT'); - expect(Through.getAttributes().UserId.onDelete).to.equal('SET NULL', 'UserId.onDelete should have been SET NULL'); - expect(Through.getAttributes().GroupId.onUpdate).to.equal('SET NULL', 'GroupId.OnUpdate should have been SET NULL'); - expect(Through.getAttributes().GroupId.onDelete).to.equal('RESTRICT', 'GroupId.onDelete should have been RESTRICT'); + expect(Through.getAttributes().userId.onUpdate).to.equal('RESTRICT', 'UserId.onUpdate should have been RESTRICT'); + expect(Through.getAttributes().userId.onDelete).to.equal('SET NULL', 'UserId.onDelete should have been SET NULL'); + expect(Through.getAttributes().groupId.onUpdate).to.equal('SET NULL', 'GroupId.OnUpdate should have been SET NULL'); + expect(Through.getAttributes().groupId.onDelete).to.equal('RESTRICT', 'GroupId.onDelete should have been RESTRICT'); }); it('makes the foreign keys primary keys', () => { @@ -976,13 +996,13 @@ describe(getTestDialectTeaser('belongsToMany'), () => { const Through = association.throughModel; - expect(Object.keys(Through.getAttributes()).sort()).to.deep.equal(['createdAt', 'updatedAt', 'GroupId', 'UserId'].sort()); - expect(Through.getAttributes().UserId.primaryKey).to.be.true; - expect(Through.getAttributes().GroupId.primaryKey).to.be.true; + expect(Object.keys(Through.getAttributes()).sort()).to.deep.equal(['createdAt', 'updatedAt', 'groupId', 'userId'].sort()); + expect(Through.getAttributes().userId.primaryKey).to.be.true; + expect(Through.getAttributes().groupId.primaryKey).to.be.true; // @ts-expect-error -- this property does not exist after normalization - expect(Through.getAttributes().UserId.unique).to.be.undefined; + expect(Through.getAttributes().userId.unique).to.be.undefined; // @ts-expect-error -- this property does not exist after normalization - expect(Through.getAttributes().GroupId.unique).to.be.undefined; + expect(Through.getAttributes().groupId.unique).to.be.undefined; }); it('generates unique identifier with very long length', () => { diff --git a/packages/core/test/unit/associations/belongs-to.test.ts b/packages/core/test/unit/associations/belongs-to.test.ts index 3e221152fa76..c49709fcdd39 100644 --- a/packages/core/test/unit/associations/belongs-to.test.ts +++ b/packages/core/test/unit/associations/belongs-to.test.ts @@ -68,6 +68,16 @@ describe(getTestDialectTeaser('belongsTo'), () => { .to.throw('Naming collision between attribute \'person\' and association \'person\' on model car. To remedy this, change the "as" options in your association definition'); }); + it('generates a default association name', () => { + const User = sequelize.define('User', {}); + const Task = sequelize.define('Task', {}); + + Task.belongsTo(User); + + expect(Object.keys(Task.associations)).to.deep.eq(['user']); + expect(Object.keys(User.associations)).to.deep.eq([]); + }); + it('should add a nullable foreign key by default', () => { const BarUser = sequelize.define('user'); @@ -84,12 +94,12 @@ describe(getTestDialectTeaser('belongsTo'), () => { Task.belongsTo(User, { foreignKey: { allowNull: false } }); - expect(Task.getAttributes().UserId.onDelete).to.eq('CASCADE'); + expect(Task.getAttributes().userId.onDelete).to.eq('CASCADE'); }); it(`does not overwrite the 'deferrable' option set in Model.init`, () => { const A = sequelize.define('A', { - BId: { + bId: { type: DataTypes.INTEGER, references: { deferrable: Deferrable.INITIALLY_IMMEDIATE, @@ -101,7 +111,7 @@ describe(getTestDialectTeaser('belongsTo'), () => { A.belongsTo(B); - expect(A.getAttributes().BId.references?.deferrable).to.equal(Deferrable.INITIALLY_IMMEDIATE); + expect(A.getAttributes().bId.references?.deferrable).to.equal(Deferrable.INITIALLY_IMMEDIATE); }); // See https://github.com/sequelize/sequelize/issues/15625 for more details @@ -149,8 +159,8 @@ describe(getTestDialectTeaser('belongsTo'), () => { Log.belongsTo(Book); - expect(Log.getAttributes().PluralId).to.not.exist; - expect(Log.getAttributes().SingularId).to.exist; + expect(Log.getAttributes().pluralId).to.not.exist; + expect(Log.getAttributes().singularId).to.exist; }); describe('association hooks', () => { diff --git a/packages/core/test/unit/associations/dont-modify-options.test.js b/packages/core/test/unit/associations/dont-modify-options.test.js index 6b6b481cd01b..e6120a576c67 100644 --- a/packages/core/test/unit/associations/dont-modify-options.test.js +++ b/packages/core/test/unit/associations/dont-modify-options.test.js @@ -29,7 +29,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { this.A.belongsTo(this.B, reqValidForeignKey); this.A.belongsTo(this.C, reqValidForeignKey); - expect(this.A.getAttributes().CId.type instanceof this.C.getAttributes().id.type.constructor); + expect(this.A.getAttributes().cId.type instanceof this.C.getAttributes().id.type.constructor); }); it('should not be overwritten for belongsToMany', function () { @@ -37,7 +37,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { this.B.belongsToMany(this.A, reqValidForeignKey); this.A.belongsTo(this.C, reqValidForeignKey); - expect(this.A.getAttributes().CId.type instanceof this.C.getAttributes().id.type.constructor); + expect(this.A.getAttributes().cId.type instanceof this.C.getAttributes().id.type.constructor); }); it('should not be overwritten for hasOne', function () { @@ -45,7 +45,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { this.B.hasOne(this.A, reqValidForeignKey); this.A.belongsTo(this.C, reqValidForeignKey); - expect(this.A.getAttributes().CId.type instanceof this.C.getAttributes().id.type.constructor); + expect(this.A.getAttributes().cId.type instanceof this.C.getAttributes().id.type.constructor); }); it('should not be overwritten for hasMany', function () { @@ -53,7 +53,7 @@ describe(Support.getTestDialectTeaser('associations'), () => { this.B.hasMany(this.A, reqValidForeignKey); this.A.belongsTo(this.C, reqValidForeignKey); - expect(this.A.getAttributes().CId.type instanceof this.C.getAttributes().id.type.constructor); + expect(this.A.getAttributes().cId.type instanceof this.C.getAttributes().id.type.constructor); }); }); }); diff --git a/packages/core/test/unit/associations/has-many.test.ts b/packages/core/test/unit/associations/has-many.test.ts index fba41f7a8bba..03d98b83cadf 100644 --- a/packages/core/test/unit/associations/has-many.test.ts +++ b/packages/core/test/unit/associations/has-many.test.ts @@ -50,6 +50,16 @@ describe(getTestDialectTeaser('hasMany'), () => { expect(User.associations.tasks).to.be.ok; }); + it('generates a default association name', () => { + const User = sequelize.define('User', {}); + const Task = sequelize.define('Task', {}); + + User.hasMany(Task); + + expect(Object.keys(Task.associations)).to.deep.eq(['user']); + expect(Object.keys(User.associations)).to.deep.eq(['tasks']); + }); + describe('optimizations using bulk create, destroy and update', () => { class User extends Model> { declare setTasks: HasManySetAssociationsMixin; diff --git a/packages/core/test/unit/associations/has-one.test.ts b/packages/core/test/unit/associations/has-one.test.ts index 5c071eb3672d..1319458a7ce7 100644 --- a/packages/core/test/unit/associations/has-one.test.ts +++ b/packages/core/test/unit/associations/has-one.test.ts @@ -60,18 +60,28 @@ describe(getTestDialectTeaser('hasOne'), () => { expect(User.associations.task).to.be.ok; }); + it('generates a default association name', () => { + const User = sequelize.define('User', {}); + const Task = sequelize.define('Task', {}); + + User.hasOne(Task); + + expect(Object.keys(Task.associations)).to.deep.eq(['user']); + expect(Object.keys(User.associations)).to.deep.eq(['task']); + }); + it('does not use `as` option to generate foreign key name', () => { // See HasOne.inferForeignKey for explanations as to why "as" is not used when inferring the foreign key. const User = sequelize.define('User', { username: DataTypes.STRING }); const Task = sequelize.define('Task', { title: DataTypes.STRING }); const association1 = User.hasOne(Task); - expect(association1.foreignKey).to.equal('UserId'); - expect(Task.getAttributes().UserId).not.to.be.empty; + expect(association1.foreignKey).to.equal('userId'); + expect(Task.getAttributes().userId).not.to.be.empty; const association2 = User.hasOne(Task, { as: 'Shabda' }); - expect(association2.foreignKey).to.equal('UserId'); - expect(Task.getAttributes().UserId).not.to.be.empty; + expect(association2.foreignKey).to.equal('userId'); + expect(Task.getAttributes().userId).not.to.be.empty; }); it('should not override custom methods with association mixin', () => { @@ -180,7 +190,7 @@ describe(getTestDialectTeaser('hasOne'), () => { User.hasOne(Task, { foreignKey: { allowNull: false } }); - expect(Task.getAttributes().UserId.onDelete).to.eq('CASCADE'); + expect(Task.getAttributes().userId.onDelete).to.eq('CASCADE'); }); it('should throw an error if an association clashes with the name of an already define attribute', () => { @@ -204,7 +214,7 @@ describe(getTestDialectTeaser('hasOne'), () => { expect( Object.keys(Group.associations), - ).to.deep.equal(['User', 'primaryUsers', 'secondaryUsers']); + ).to.deep.equal(['user', 'primaryUsers', 'secondaryUsers']); }); }); diff --git a/packages/core/test/unit/query-generator/select-query.test.ts b/packages/core/test/unit/query-generator/select-query.test.ts index f269bb91bb3a..0224c0bb5ca4 100644 --- a/packages/core/test/unit/query-generator/select-query.test.ts +++ b/packages/core/test/unit/query-generator/select-query.test.ts @@ -3,7 +3,7 @@ import type { CreationOptional, InferAttributes, InferCreationAttributes, Model import { DataTypes, IndexHints, Op, TableHints, or, sql as sqlTag } from '@sequelize/core'; import { _validateIncludedElements } from '@sequelize/core/_non-semver-use-at-your-own-risk_/model-internals.js'; import { buildInvalidOptionReceivedError } from '@sequelize/core/_non-semver-use-at-your-own-risk_/utils/check.js'; -import { expectsql, getTestDialect, sequelize } from '../../support'; +import { beforeAll2, expectsql, getTestDialect, sequelize } from '../../support'; const { attribute, col, cast, where, fn, literal } = sqlTag; const dialectName = getTestDialect(); @@ -11,48 +11,55 @@ const dialectName = getTestDialect(); describe('QueryGenerator#selectQuery', () => { const queryGenerator = sequelize.queryGenerator; - interface TUser extends Model, InferCreationAttributes> { - id: CreationOptional; - username: string; - } + const vars = beforeAll2(() => { + interface TUser extends Model, InferCreationAttributes> { + id: CreationOptional; + username: string; + } + + const User = sequelize.define('User', { + id: { + type: DataTypes.INTEGER.UNSIGNED, + autoIncrement: true, + primaryKey: true, + }, + username: DataTypes.STRING, + }, { timestamps: true }); + + interface TProject extends Model, InferCreationAttributes> { + id: CreationOptional; + duration: bigint; + } + + const Project = sequelize.define('Project', { + id: { + type: DataTypes.INTEGER.UNSIGNED, + autoIncrement: true, + primaryKey: true, + }, + duration: DataTypes.BIGINT, + }, { timestamps: false }); - const User = sequelize.define('User', { - id: { - type: DataTypes.INTEGER.UNSIGNED, - autoIncrement: true, - primaryKey: true, - }, - username: DataTypes.STRING, - }, { timestamps: true }); - - interface TProject extends Model, InferCreationAttributes> { - id: CreationOptional; - duration: bigint; - } + const ProjectContributor = sequelize.define('ProjectContributor', {}, { timestamps: false }); + + // project owners + User.hasMany(Project, { as: 'projects' }); + Project.belongsTo(User, { as: 'owner' }); - const Project = sequelize.define('Project', { - id: { - type: DataTypes.INTEGER.UNSIGNED, - autoIncrement: true, - primaryKey: true, - }, - duration: DataTypes.BIGINT, - }, { timestamps: false }); - - const ProjectContributor = sequelize.define('ProjectContributor', {}, { timestamps: false }); - - // project owners - User.hasMany(Project, { as: 'projects' }); - Project.belongsTo(User, { as: 'owner' }); - - // project contributors - Project.belongsToMany(User, { - through: ProjectContributor, - as: 'contributors', + // project contributors + Project.belongsToMany(User, { + through: ProjectContributor, + as: 'contributors', + inverse: 'contributedProjects', + }); + + return { User, Project, ProjectContributor }; }); describe('limit/offset', () => { it('supports offset without limit', () => { + const { User } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -69,6 +76,8 @@ describe('QueryGenerator#selectQuery', () => { }); it('support limit without offset', () => { + const { User } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -83,6 +92,8 @@ describe('QueryGenerator#selectQuery', () => { }); it('supports offset and limit', () => { + const { User } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -97,6 +108,8 @@ describe('QueryGenerator#selectQuery', () => { }); it('ignores 0 as offset with a limit', () => { + const { User } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -112,6 +125,8 @@ describe('QueryGenerator#selectQuery', () => { }); it('ignores 0 as offset without a limit', () => { + const { User } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -124,6 +139,8 @@ describe('QueryGenerator#selectQuery', () => { }); it('support 0 as limit', () => { + const { User } = vars; + expectsql(() => queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -136,6 +153,8 @@ describe('QueryGenerator#selectQuery', () => { }); it('escapes limit', () => { + const { User } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -152,6 +171,8 @@ describe('QueryGenerator#selectQuery', () => { }); it('escapes offset', () => { + const { User } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -170,6 +191,8 @@ describe('QueryGenerator#selectQuery', () => { }); it('supports querying for bigint values', () => { + const { Project } = vars; + const sql = queryGenerator.selectQuery(Project.table, { model: Project, attributes: ['id'], @@ -184,6 +207,8 @@ describe('QueryGenerator#selectQuery', () => { }); it('supports cast in attributes', () => { + const { User } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: [ @@ -198,6 +223,8 @@ describe('QueryGenerator#selectQuery', () => { }); it('supports empty where object', () => { + const { User } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: [ @@ -212,6 +239,8 @@ describe('QueryGenerator#selectQuery', () => { }); it('escapes WHERE clause correctly', () => { + const { User } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: [ @@ -229,6 +258,8 @@ describe('QueryGenerator#selectQuery', () => { if (sequelize.dialect.supports.jsonOperations && sequelize.dialect.supports.jsonExtraction.quoted) { it('accepts json paths in attributes', () => { + const { User } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: [ @@ -246,6 +277,8 @@ describe('QueryGenerator#selectQuery', () => { describe('replacements', () => { it('parses named replacements in literals', () => { + const { User } = vars; + // The goal of this test is to test that :replacements are parsed in literals in as many places as possible const sql = queryGenerator.selectQuery(User.table, { @@ -316,6 +349,8 @@ describe('QueryGenerator#selectQuery', () => { // see the unit tests of 'injectReplacements' for more it('does not parse replacements in strings in literals', () => { + const { User } = vars; + // The goal of this test is to test that :replacements are parsed in literals in as many places as possible const sql = queryGenerator.selectQuery(User.table, { @@ -333,6 +368,8 @@ describe('QueryGenerator#selectQuery', () => { }); it('parses named replacements in literals in includes', () => { + const { User, Project } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -404,6 +441,8 @@ describe('QueryGenerator#selectQuery', () => { }); it(`parses named replacements in belongsToMany includes' through tables`, () => { + const { Project } = vars; + const sql = queryGenerator.selectQuery(Project.table, { model: Project, attributes: ['id'], @@ -427,36 +466,38 @@ describe('QueryGenerator#selectQuery', () => { SELECT [Project].[id], [contributors].[id] AS [contributors.id], - [contributors->ProjectContributor].[UserId] AS [contributors.ProjectContributor.UserId], - [contributors->ProjectContributor].[ProjectId] AS [contributors.ProjectContributor.ProjectId] + [contributors->ProjectContributor].[userId] AS [contributors.ProjectContributor.userId], + [contributors->ProjectContributor].[projectId] AS [contributors.ProjectContributor.projectId] FROM [Projects] AS [Project] LEFT OUTER JOIN ( [ProjectContributors] AS [contributors->ProjectContributor] INNER JOIN [Users] AS [contributors] - ON [contributors].[id] = [contributors->ProjectContributor].[UserId] + ON [contributors].[id] = [contributors->ProjectContributor].[userId] AND 'where' ) - ON [Project].[id] = [contributors->ProjectContributor].[ProjectId]; + ON [Project].[id] = [contributors->ProjectContributor].[projectId]; `, mssql: ` SELECT [Project].[id], [contributors].[id] AS [contributors.id], - [contributors->ProjectContributor].[UserId] AS [contributors.ProjectContributor.UserId], - [contributors->ProjectContributor].[ProjectId] AS [contributors.ProjectContributor.ProjectId] + [contributors->ProjectContributor].[userId] AS [contributors.ProjectContributor.userId], + [contributors->ProjectContributor].[projectId] AS [contributors.ProjectContributor.projectId] FROM [Projects] AS [Project] LEFT OUTER JOIN ( [ProjectContributors] AS [contributors->ProjectContributor] INNER JOIN [Users] AS [contributors] - ON [contributors].[id] = [contributors->ProjectContributor].[UserId] + ON [contributors].[id] = [contributors->ProjectContributor].[userId] AND N'where' ) - ON [Project].[id] = [contributors->ProjectContributor].[ProjectId]; + ON [Project].[id] = [contributors->ProjectContributor].[projectId]; `, }); }); it('parses named replacements in literals in includes (subQuery)', () => { + const { User, Project } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -575,6 +616,8 @@ describe('QueryGenerator#selectQuery', () => { }); it('rejects positional replacements, because their execution order is hard to determine', () => { + const { User } = vars; + expect( () => queryGenerator.selectQuery(User.table, { model: User, @@ -591,6 +634,8 @@ Only named replacements (:name) are allowed in literal() because we cannot guara }); it(`always escapes the attribute if it's provided as a string`, () => { + const { User } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: [ @@ -641,6 +686,8 @@ Only named replacements (:name) are allowed in literal() because we cannot guara }); it('supports a "having" option', () => { + const { User } = vars; + const sql = queryGenerator.selectQuery(User.table, { model: User, attributes: [ @@ -751,6 +798,8 @@ Only named replacements (:name) are allowed in literal() because we cannot guara describe('minifyAliases', () => { it('minifies custom attributes', () => { + const { User } = vars; + const sql = queryGenerator.selectQuery(User.table, { minifyAliases: true, model: User, @@ -769,6 +818,8 @@ Only named replacements (:name) are allowed in literal() because we cannot guara describe('optimizer hints', () => { it('max execution time hint', () => { + const { User } = vars; + const notSupportedError = new Error(`The maxExecutionTimeMs option is not supported by ${dialectName}`); expectsql(() => queryGenerator.selectQuery(User.tableName, { @@ -784,6 +835,8 @@ Only named replacements (:name) are allowed in literal() because we cannot guara describe('index hints', () => { it('should add an index hint', () => { + const { User } = vars; + expectsql(() => queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -795,6 +848,8 @@ Only named replacements (:name) are allowed in literal() because we cannot guara }); it('should add an index hint with multiple values', () => { + const { User } = vars; + expectsql(() => queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -806,6 +861,8 @@ Only named replacements (:name) are allowed in literal() because we cannot guara }); it('should throw an error if an index hint if the type is not valid', () => { + const { User } = vars; + expectsql(() => queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -820,6 +877,8 @@ Only named replacements (:name) are allowed in literal() because we cannot guara describe('table hints', () => { it('support an array of table hints', () => { + const { User } = vars; + expectsql(() => queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -831,6 +890,8 @@ Only named replacements (:name) are allowed in literal() because we cannot guara }); it('should be able to use table hints on joins', () => { + const { User } = vars; + expectsql(() => queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -844,11 +905,13 @@ Only named replacements (:name) are allowed in literal() because we cannot guara }).include, }, User), { default: buildInvalidOptionReceivedError('quoteTable', sequelize.dialect.name, ['tableHints']), - mssql: `SELECT [User].[id], [projects].[id] AS [projects.id] FROM [Users] AS [User] WITH (NOLOCK) LEFT OUTER JOIN [Projects] AS [projects] WITH (NOLOCK) ON [User].[id] = [projects].[UserId];`, + mssql: `SELECT [User].[id], [projects].[id] AS [projects.id] FROM [Users] AS [User] WITH (NOLOCK) LEFT OUTER JOIN [Projects] AS [projects] WITH (NOLOCK) ON [User].[id] = [projects].[userId];`, }); }); it('should be able to use separate table hints on joins', () => { + const { User } = vars; + expectsql(() => queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], @@ -863,11 +926,13 @@ Only named replacements (:name) are allowed in literal() because we cannot guara }).include, }, User), { default: buildInvalidOptionReceivedError('quoteTable', sequelize.dialect.name, ['tableHints']), - mssql: `SELECT [User].[id], [projects].[id] AS [projects.id] FROM [Users] AS [User] WITH (NOLOCK) LEFT OUTER JOIN [Projects] AS [projects] WITH (READPAST) ON [User].[id] = [projects].[UserId];`, + mssql: `SELECT [User].[id], [projects].[id] AS [projects.id] FROM [Users] AS [User] WITH (NOLOCK) LEFT OUTER JOIN [Projects] AS [projects] WITH (READPAST) ON [User].[id] = [projects].[userId];`, }); }); it('should throw an error if a table hint if the type is not valid', () => { + const { User } = vars; + expectsql(() => queryGenerator.selectQuery(User.table, { model: User, attributes: ['id'], diff --git a/packages/core/test/unit/sql/generateJoin.test.js b/packages/core/test/unit/sql/generateJoin.test.js index 655bb061fbd0..26424095cd43 100644 --- a/packages/core/test/unit/sql/generateJoin.test.js +++ b/packages/core/test/unit/sql/generateJoin.test.js @@ -79,11 +79,11 @@ describe(Support.getTestDialectTeaser('SQL'), () => { tableName: 'profession', }); - User.Tasks = User.hasMany(Task, { as: 'Tasks', foreignKey: 'userId' }); - User.Company = User.belongsTo(Company, { foreignKey: 'companyId' }); - User.Profession = User.belongsTo(Profession, { foreignKey: 'professionId' }); - Profession.Professionals = Profession.hasMany(User, { as: 'Professionals', foreignKey: 'professionId' }); - Company.Employees = Company.hasMany(User, { as: 'Employees', foreignKey: 'companyId' }); + User.Tasks = User.hasMany(Task, { as: 'Tasks', foreignKey: 'userId', inverse: 'User' }); + User.Company = User.belongsTo(Company, { as: 'Company', foreignKey: 'companyId' }); + User.Profession = User.belongsTo(Profession, { as: 'Profession', foreignKey: 'professionId' }); + Profession.Professionals = Profession.hasMany(User, { as: 'Professionals', foreignKey: 'professionId', inverse: 'Profession' }); + Company.Employees = Company.hasMany(User, { as: 'Employees', foreignKey: 'companyId', inverse: 'Company' }); Company.Owner = Company.belongsTo(User, { as: 'Owner', foreignKey: 'ownerId' }); /* diff --git a/packages/core/test/unit/sql/order.test.js b/packages/core/test/unit/sql/order.test.js index a46c223d41ca..604719f8fa10 100644 --- a/packages/core/test/unit/sql/order.test.js +++ b/packages/core/test/unit/sql/order.test.js @@ -186,6 +186,7 @@ describe(Support.getTestDialectTeaser('SQL'), () => { Project.hasMany(Task, { as: 'Tasks', foreignKey: 'project_id', + inverse: 'Project', }); Task.belongsTo(Project, { @@ -196,6 +197,7 @@ describe(Support.getTestDialectTeaser('SQL'), () => { Task.hasMany(Subtask, { as: 'Subtasks', foreignKey: 'task_id', + inverse: 'Task', }); Subtask.belongsTo(Task, { diff --git a/packages/core/test/unit/sql/select.test.js b/packages/core/test/unit/sql/select.test.js index d57204060e51..a229fa13f2f7 100644 --- a/packages/core/test/unit/sql/select.test.js +++ b/packages/core/test/unit/sql/select.test.js @@ -614,8 +614,8 @@ describe(Support.getTestDialectTeaser('SQL'), () => { }).include, model: User, }, User), { - ibmi: 'SELECT "User"."name", "User"."age", "Posts"."id" AS "Posts.id", "Posts"."title" AS "Posts.title" FROM "User" AS "User" LEFT OUTER JOIN "Post" AS "Posts" ON "User"."id" = "Posts"."user_id"', - default: 'SELECT [User].[name], [User].[age], [Posts].[id] AS [Posts.id], [Posts].[title] AS [Posts.title] FROM [User] AS [User] LEFT OUTER JOIN [Post] AS [Posts] ON [User].[id] = [Posts].[user_id];', + ibmi: 'SELECT "User"."name", "User"."age", "posts"."id" AS "posts.id", "posts"."title" AS "posts.title" FROM "User" AS "User" LEFT OUTER JOIN "Post" AS "posts" ON "User"."id" = "posts"."user_id"', + default: 'SELECT [User].[name], [User].[age], [posts].[id] AS [posts.id], [posts].[title] AS [posts.title] FROM [User] AS [User] LEFT OUTER JOIN [Post] AS [posts] ON [User].[id] = [posts].[user_id];', }); }); @@ -648,7 +648,7 @@ describe(Support.getTestDialectTeaser('SQL'), () => { }).include, model: User, }, User), { - default: `SELECT [User].[name], [User].[age], [Posts].[id] AS [Posts.id], [Posts].[title] AS [Posts.title] FROM [User] AS [User] ${current.dialect.supports['RIGHT JOIN'] ? 'RIGHT' : 'LEFT'} OUTER JOIN [Post] AS [Posts] ON [User].[id] = [Posts].[user_id];`, + default: `SELECT [User].[name], [User].[age], [posts].[id] AS [posts.id], [posts].[title] AS [posts.title] FROM [User] AS [User] ${current.dialect.supports['RIGHT JOIN'] ? 'RIGHT' : 'LEFT'} OUTER JOIN [Post] AS [posts] ON [User].[id] = [posts].[user_id];`, }); }); @@ -823,7 +823,7 @@ describe(Support.getTestDialectTeaser('SQL'), () => { table: Company.getTableName(), model: Company, attributes: ['name', 'public'], - where: { '$Users.Profession.name$': 'test', [Op.and]: { scopeId: [42] } }, + where: { '$Users.profession.name$': 'test', [Op.and]: { scopeId: [42] } }, include: _validateIncludedElements({ include: [{ association: Company.Users, @@ -845,28 +845,28 @@ describe(Support.getTestDialectTeaser('SQL'), () => { default: 'SELECT [Company].* FROM (' + 'SELECT [Company].[name], [Company].[public], [Company].[id] FROM [Company] AS [Company] ' + 'INNER JOIN [Users] AS [Users] ON [Company].[id] = [Users].[companyId] ' - + 'INNER JOIN [Professions] AS [Users->Profession] ON [Users].[professionId] = [Users->Profession].[id] ' - + `WHERE ([Company].[scopeId] IN (42) AND [Users->Profession].[name] = ${sql.escape('test')}) AND ( ` + + 'INNER JOIN [Professions] AS [Users->profession] ON [Users].[professionId] = [Users->profession].[id] ' + + `WHERE ([Company].[scopeId] IN (42) AND [Users->profession].[name] = ${sql.escape('test')}) AND ( ` + 'SELECT [Users].[companyId] FROM [Users] AS [Users] ' - + 'INNER JOIN [Professions] AS [Profession] ON [Users].[professionId] = [Profession].[id] ' + + 'INNER JOIN [Professions] AS [profession] ON [Users].[professionId] = [profession].[id] ' + `WHERE [Users].[companyId] = [Company].[id] ORDER BY [Users].[id] LIMIT 1` + `) IS NOT NULL ORDER BY [Company].[id] LIMIT 5) AS [Company];`, 'db2 ibmi': 'SELECT [Company].* FROM (' + 'SELECT [Company].[name], [Company].[public], [Company].[id] FROM [Company] AS [Company] ' + 'INNER JOIN [Users] AS [Users] ON [Company].[id] = [Users].[companyId] ' - + 'INNER JOIN [Professions] AS [Users->Profession] ON [Users].[professionId] = [Users->Profession].[id] ' - + `WHERE ([Company].[scopeId] IN (42) AND [Users->Profession].[name] = ${sql.escape('test')}) AND ( ` + + 'INNER JOIN [Professions] AS [Users->profession] ON [Users].[professionId] = [Users->profession].[id] ' + + `WHERE ([Company].[scopeId] IN (42) AND [Users->profession].[name] = ${sql.escape('test')}) AND ( ` + 'SELECT [Users].[companyId] FROM [Users] AS [Users] ' - + 'INNER JOIN [Professions] AS [Profession] ON [Users].[professionId] = [Profession].[id] ' + + 'INNER JOIN [Professions] AS [profession] ON [Users].[professionId] = [profession].[id] ' + `WHERE [Users].[companyId] = [Company].[id] ORDER BY [Users].[id] FETCH NEXT 1 ROWS ONLY` + `) IS NOT NULL ORDER BY [Company].[id] FETCH NEXT 5 ROWS ONLY) AS [Company];`, mssql: 'SELECT [Company].* FROM (' + 'SELECT [Company].[name], [Company].[public], [Company].[id] FROM [Company] AS [Company] ' + 'INNER JOIN [Users] AS [Users] ON [Company].[id] = [Users].[companyId] ' - + 'INNER JOIN [Professions] AS [Users->Profession] ON [Users].[professionId] = [Users->Profession].[id] ' - + `WHERE ([Company].[scopeId] IN (42) AND [Users->Profession].[name] = ${sql.escape('test')}) AND ( ` + + 'INNER JOIN [Professions] AS [Users->profession] ON [Users].[professionId] = [Users->profession].[id] ' + + `WHERE ([Company].[scopeId] IN (42) AND [Users->profession].[name] = ${sql.escape('test')}) AND ( ` + 'SELECT [Users].[companyId] FROM [Users] AS [Users] ' - + 'INNER JOIN [Professions] AS [Profession] ON [Users].[professionId] = [Profession].[id] ' + + 'INNER JOIN [Professions] AS [profession] ON [Users].[professionId] = [profession].[id] ' + `WHERE [Users].[companyId] = [Company].[id] ORDER BY [Users].[id] OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY` + `) IS NOT NULL ORDER BY [Company].[id] OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY) AS [Company];`, }); @@ -992,7 +992,8 @@ describe(Support.getTestDialectTeaser('SQL'), () => { freezeTableName: true, }); - User.Posts = User.hasMany(Post, { foreignKey: 'user_id' }); + // association name is Pascal case to test quoteIdentifier: false + User.Posts = User.hasMany(Post, { foreignKey: 'user_id', as: 'Posts' }); expectsql(sql.selectQuery('User', { attributes: ['name', 'age'], @@ -1058,7 +1059,7 @@ describe(Support.getTestDialectTeaser('SQL'), () => { }); }); - describe('queryIdentifiers: false', () => { + describe('quoteIdentifiers: false', () => { beforeEach(() => { sql.options.quoteIdentifiers = false; }); @@ -1101,7 +1102,8 @@ describe(Support.getTestDialectTeaser('SQL'), () => { freezeTableName: true, }); - User.Posts = User.hasMany(Post, { foreignKey: 'user_id' }); + // association name is Pascal case to test quoteIdentifier: false + User.Posts = User.hasMany(Post, { foreignKey: 'user_id', as: 'Posts' }); expectsql(sql.selectQuery('User', { attributes: ['name', 'age'], @@ -1142,8 +1144,9 @@ describe(Support.getTestDialectTeaser('SQL'), () => { freezeTableName: true, }); - User.Posts = User.hasMany(Post, { foreignKey: 'user_id' }); - Post.Comments = Post.hasMany(Comment, { foreignKey: 'post_id' }); + // association names are Pascal case to test quoteIdentifier: false + User.Posts = User.hasMany(Post, { foreignKey: 'user_id', as: 'Posts' }); + Post.Comments = Post.hasMany(Comment, { foreignKey: 'post_id', as: 'Comments' }); expectsql(sql.selectQuery('User', { attributes: ['name', 'age'], @@ -1189,7 +1192,8 @@ describe(Support.getTestDialectTeaser('SQL'), () => { freezeTableName: true, }); - User.Posts = User.hasMany(Post, { foreignKey: 'user_id' }); + // association name is Pascal case to test quoteIdentifier: false + User.Posts = User.hasMany(Post, { foreignKey: 'user_id', as: 'Posts' }); expectsql(sql.selectQuery('User', { attributes: ['name', 'age', ['status.label', 'statuslabel']], diff --git a/packages/core/test/unit/utils/utils.test.ts b/packages/core/test/unit/utils/utils.test.ts index 9730cadf219a..7bfbd789afe4 100644 --- a/packages/core/test/unit/utils/utils.test.ts +++ b/packages/core/test/unit/utils/utils.test.ts @@ -9,12 +9,7 @@ import { flattenObjectDeep, merge, } from '@sequelize/core/_non-semver-use-at-your-own-risk_/utils/object.js'; -import { - camelizeIf, - pluralize, - singularize, - underscoredIf, -} from '@sequelize/core/_non-semver-use-at-your-own-risk_/utils/string.js'; +import { pluralize, singularize, underscoredIf } from '@sequelize/core/_non-semver-use-at-your-own-risk_/utils/string.js'; import { parseConnectionString } from '@sequelize/core/_non-semver-use-at-your-own-risk_/utils/url.js'; import { sequelize } from '../../support'; @@ -35,20 +30,6 @@ describe('Utils', () => { expect(underscoredIf('fooBar', false)).to.equal('fooBar'); }); }); - - describe('camelizeIf', () => { - it('is defined', () => { - expect(camelizeIf).to.be.ok; - }); - - it('camelizes if second param is true', () => { - expect(camelizeIf('foo_bar', true)).to.equal('fooBar'); - }); - - it('doesn\'t camelize if second param is false', () => { - expect(underscoredIf('fooBar', true)).to.equal('foo_bar'); - }); - }); }); describe('cloneDeep', () => {