diff --git a/src/sscce-sequelize-6.ts b/src/sscce-sequelize-6.ts index 132a311d5..1a592a9b0 100644 --- a/src/sscce-sequelize-6.ts +++ b/src/sscce-sequelize-6.ts @@ -6,8 +6,6 @@ import sinon from 'sinon'; // if your issue is dialect specific, remove the dialects you don't need to test on. export const testingOnDialects = new Set(['mssql', 'sqlite', 'mysql', 'mariadb', 'postgres', 'postgres-native']); -// You can delete this file if you don't want your SSCCE to be tested against Sequelize 6 - // Your SSCCE goes inside this function. export async function run() { // This function should be used instead of `new Sequelize()`. @@ -18,17 +16,66 @@ export async function run() { define: { // For less clutter in the SSCCE timestamps: false, + underscored: true }, }); - class Foo extends Model {} - - Foo.init({ +class Parents extends Model {}; +Parents.init( + { + id: { + type: DataTypes.INTEGER, + autoIncrement: true, + primaryKey: true, + }, name: DataTypes.TEXT, - }, { - sequelize, - modelName: 'Foo', - }); + }, + {sequelize}, +); + +class Children extends Model {}; +Children.init( + { + id: { + type: DataTypes.INTEGER, + autoIncrement: true, + primaryKey: true, + }, + parentId: { + type: DataTypes.INTEGER, + references: { + model: Parents, + key: 'id' + } + } + }, + {sequelize} + +) + +class GrandChildren extends Model {}; +GrandChildren.init( + { + id: { + type: DataTypes.INTEGER, + autoIncrement: true, + primaryKey: true, + }, + parentId: { + type: DataTypes.INTEGER, + references: { + model: Children, + key: 'id' + } + } + }, + {sequelize} +); + +Parents.hasMany(Children) +Children.belongsTo(Parents) +Children.hasMany(GrandChildren) +GrandChildren.belongsTo(Children) // You can use sinon and chai assertions directly in your SSCCE. const spy = sinon.spy(); @@ -36,6 +83,24 @@ export async function run() { await sequelize.sync({ force: true }); expect(spy).to.have.been.called; - console.log(await Foo.create({ name: 'TS foo' })); - expect(await Foo.count()).to.equal(1); + const created = await Parents.create() + const {rows, count} = await Parents.findAndCountAll({ + include: { + model: Children, + required: false, + include: [{ + model: GrandChildren, + required: true, + }] + }, + limit: 1 + }) + + console.log(rows); + expect(created).to.not.be.undefined; + expect(created).to.not.be.null; + expect(count).to.equal(1); + expect(rows.length).to.equal(1); } + + diff --git a/src/sscce-sequelize-7.ts b/src/sscce-sequelize-7.ts index 603cb219c..a54a445e2 100644 --- a/src/sscce-sequelize-7.ts +++ b/src/sscce-sequelize-7.ts @@ -1,4 +1,4 @@ -import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model } from '@sequelize/core'; +import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model, DialectOptions } from '@sequelize/core'; import { Attribute, NotNull } from '@sequelize/core/decorators-legacy'; import { createSequelize7Instance } from '../dev/create-sequelize-instance'; import { expect } from 'chai'; @@ -13,31 +13,96 @@ export const testingOnDialects = new Set(['mssql', 'sqlite', 'mysql', 'mariadb', export async function run() { // This function should be used instead of `new Sequelize()`. // It applies the config for your SSCCE to work on CI. + const sequelize = createSequelize7Instance({ logQueryParameters: true, benchmark: true, define: { // For less clutter in the SSCCE timestamps: false, + underscored: true }, }); - class Foo extends Model, InferCreationAttributes> { - declare id: CreationOptional; + class Parents extends Model {}; + Parents.init( + { + id: { + type: DataTypes.INTEGER, + autoIncrement: true, + primaryKey: true, + }, + name: DataTypes.TEXT, + }, + {sequelize}, + ); + + class Children extends Model {}; + Children.init( + { + id: { + type: DataTypes.INTEGER, + autoIncrement: true, + primaryKey: true, + }, + parentId: { + type: DataTypes.INTEGER, + references: { + model: Parents, + key: 'id' + } + } + }, + {sequelize} + + ) + + class GrandChildren extends Model {}; + GrandChildren.init( + { + id: { + type: DataTypes.INTEGER, + autoIncrement: true, + primaryKey: true, + }, + parentId: { + type: DataTypes.INTEGER, + references: { + model: Children, + key: 'id' + } + } + }, + {sequelize} + ); - @Attribute(DataTypes.TEXT) - @NotNull - declare name: string; - } + Parents.hasMany(Children) + Children.belongsTo(Parents) + Children.hasMany(GrandChildren) + GrandChildren.belongsTo(Children) - sequelize.addModels([Foo]); + // You can use sinon and chai assertions directly in your SSCCE. + const spy = sinon.spy(); + sequelize.afterBulkSync(() => spy()); + await sequelize.sync({ force: true }); + expect(spy).to.have.been.called; - // You can use sinon and chai assertions directly in your SSCCE. - const spy = sinon.spy(); - sequelize.afterBulkSync(() => spy()); - await sequelize.sync({ force: true }); - expect(spy).to.have.been.called; + const created = await Parents.create() + const {rows, count} = await Parents.findAndCountAll({ + include: { + model: Children, + required: false, + include: [{ + model: GrandChildren, + required: true, + }] + }, + limit: 1 + }) - console.log(await Foo.create({ name: 'TS foo' })); - expect(await Foo.count()).to.equal(1); + console.log(rows); + expect(created).to.not.be.undefined; + expect(created).to.not.be.null; + expect(count).to.equal(1); + expect(rows.length).to.equal(1); }