diff --git a/CHANGELOG.md b/CHANGELOG.md index 543c2231ccbf..6ca671f23fcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.6](https://github.com/mikro-orm/mikro-orm/compare/v4.0.5...v4.0.6) (2020-09-22) + + +### Bug Fixes + +* **deps:** update dependency escaya to ^0.0.49 ([#854](https://github.com/mikro-orm/mikro-orm/issues/854)) ([d4737b6](https://github.com/mikro-orm/mikro-orm/commit/d4737b646fe52c5bf4797312835cc974f4fe7b7c)) +* **migrations:** migrate only one version down with explicit tx ([50567dd](https://github.com/mikro-orm/mikro-orm/commit/50567ddd384ac2b53512925cade28e8debbb9f3b)), closes [#855](https://github.com/mikro-orm/mikro-orm/issues/855) +* **query-builder:** do not select 1:1 owner when auto-joining ([86c3032](https://github.com/mikro-orm/mikro-orm/commit/86c303229c2ac7b77d245000f64562c0cc529320)), closes [#858](https://github.com/mikro-orm/mikro-orm/issues/858) +* **query-builder:** fix auto-joining of 1:m PKs ([920995f](https://github.com/mikro-orm/mikro-orm/commit/920995f94070ff242b297d2837d83c7d9a9cb776)), closes [#857](https://github.com/mikro-orm/mikro-orm/issues/857) +* **query-builder:** fix count query with auto-joining of 1:1 ([9b8056c](https://github.com/mikro-orm/mikro-orm/commit/9b8056c7440b836d22c8175ba90adf70fc3b052e)), closes [#858](https://github.com/mikro-orm/mikro-orm/issues/858) +* **query-builder:** wrap nested array conditions with `$in` operator ([939989a](https://github.com/mikro-orm/mikro-orm/commit/939989add4f670deefe44f5a7faedb9b64155ba5)), closes [#860](https://github.com/mikro-orm/mikro-orm/issues/860) + + + + + ## [4.0.5](https://github.com/mikro-orm/mikro-orm/compare/v4.0.4...v4.0.5) (2020-09-21) diff --git a/lerna.json b/lerna.json index 088addd4f31f..0d65332e96b8 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "packages": [ "packages/*" ], - "version": "4.0.5", + "version": "4.0.6", "command": { "version": { "conventionalCommits": true, diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 014f85bbdbca..36eddbd53910 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.6](https://github.com/mikro-orm/mikro-orm/compare/v4.0.5...v4.0.6) (2020-09-22) + +**Note:** Version bump only for package @mikro-orm/cli + + + + + ## [4.0.5](https://github.com/mikro-orm/mikro-orm/compare/v4.0.4...v4.0.5) (2020-09-21) **Note:** Version bump only for package @mikro-orm/cli diff --git a/packages/cli/package.json b/packages/cli/package.json index 9f794e2a38c1..5ad18eb37629 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@mikro-orm/cli", - "version": "4.0.5", + "version": "4.0.6", "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -50,10 +50,10 @@ "access": "public" }, "dependencies": { - "@mikro-orm/core": "^4.0.5", - "@mikro-orm/entity-generator": "^4.0.5", - "@mikro-orm/knex": "^4.0.5", - "@mikro-orm/migrations": "^4.0.5", + "@mikro-orm/core": "^4.0.6", + "@mikro-orm/entity-generator": "^4.0.6", + "@mikro-orm/knex": "^4.0.6", + "@mikro-orm/migrations": "^4.0.6", "ansi-colors": "^4.1.1", "cli-table3": "^0.6.0", "fs-extra": "^9.0.1", diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 9560d5cb265e..617f5b2df600 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.6](https://github.com/mikro-orm/mikro-orm/compare/v4.0.5...v4.0.6) (2020-09-22) + + +### Bug Fixes + +* **deps:** update dependency escaya to ^0.0.49 ([#854](https://github.com/mikro-orm/mikro-orm/issues/854)) ([d4737b6](https://github.com/mikro-orm/mikro-orm/commit/d4737b646fe52c5bf4797312835cc974f4fe7b7c)) +* **query-builder:** wrap nested array conditions with `$in` operator ([939989a](https://github.com/mikro-orm/mikro-orm/commit/939989add4f670deefe44f5a7faedb9b64155ba5)), closes [#860](https://github.com/mikro-orm/mikro-orm/issues/860) + + + + + ## [4.0.5](https://github.com/mikro-orm/mikro-orm/compare/v4.0.4...v4.0.5) (2020-09-21) diff --git a/packages/core/package.json b/packages/core/package.json index 78d34a2e7b06..64968e35ae52 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@mikro-orm/core", - "version": "4.0.5", + "version": "4.0.6", "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -49,7 +49,7 @@ "dependencies": { "ansi-colors": "^4.1.1", "clone": "^2.1.2", - "escaya": "^0.0.47", + "escaya": "^0.0.49", "fast-deep-equal": "^3.1.3", "fs-extra": "^9.0.1", "globby": "^11.0.1", diff --git a/packages/core/src/utils/QueryHelper.ts b/packages/core/src/utils/QueryHelper.ts index ceb25467c6ca..3ebf5fb739ee 100644 --- a/packages/core/src/utils/QueryHelper.ts +++ b/packages/core/src/utils/QueryHelper.ts @@ -73,7 +73,7 @@ export class QueryHelper { const meta = metadata.find(entityName); // inline PK-only objects in M:N queries so we don't join the target entity when not needed - if (meta) { + if (meta && root) { QueryHelper.inlinePrimaryKeyObjects(where as Dictionary, meta, metadata); } @@ -87,7 +87,7 @@ export class QueryHelper { where = { [Utils.getPrimaryKeyHash(meta.primaryKeys)]: where }; } - if (Array.isArray(where)) { + if (Array.isArray(where) && root) { const rootPrimaryKey = meta ? Utils.getPrimaryKeyHash(meta.primaryKeys) : entityName; return { [rootPrimaryKey]: { $in: (where as FilterQuery[]).map(sub => QueryHelper.processWhere(sub, entityName, metadata, platform, convertCustomTypes, false)) } } as FilterQuery; } @@ -107,18 +107,27 @@ export class QueryHelper { return o; } + // wrap top level operators (except $not) with PK + if (Utils.isOperator(key) && root && meta && key !== '$not') { + const rootPrimaryKey = Utils.getPrimaryKeyHash(meta.primaryKeys); + o[rootPrimaryKey] = { [key]: QueryHelper.processWhere(value, entityName, metadata, platform, convertCustomTypes, false) }; + return o; + } + if (prop?.customType && convertCustomTypes) { value = QueryHelper.processCustomType(prop, value, platform, undefined, true); } - if (Array.isArray(value) && !QueryHelper.isSupportedOperator(key) && !key.includes('?')) { + if (Array.isArray(value) && !Utils.isOperator(key) && !QueryHelper.isSupportedOperator(key) && !key.includes('?')) { // comparing single composite key - use $eq instead of $in const op = !value.every(v => Array.isArray(v)) && composite ? '$eq' : '$in'; o[key] = { [op]: value }; return o; } - if (!QueryHelper.isSupportedOperator(key)) { + if (Utils.isPlainObject(value)) { + o[key] = QueryHelper.processWhere(value, prop?.type ?? entityName, metadata, platform, convertCustomTypes, false); + } else if (!QueryHelper.isSupportedOperator(key)) { o[key] = value; } else if (key.includes(':')) { const [k, expr] = key.split(':'); diff --git a/packages/entity-generator/CHANGELOG.md b/packages/entity-generator/CHANGELOG.md index ec5a3127dfd9..ff851ea5d438 100644 --- a/packages/entity-generator/CHANGELOG.md +++ b/packages/entity-generator/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.6](https://github.com/mikro-orm/mikro-orm/compare/v4.0.5...v4.0.6) (2020-09-22) + +**Note:** Version bump only for package @mikro-orm/entity-generator + + + + + ## [4.0.5](https://github.com/mikro-orm/mikro-orm/compare/v4.0.4...v4.0.5) (2020-09-21) **Note:** Version bump only for package @mikro-orm/entity-generator diff --git a/packages/entity-generator/package.json b/packages/entity-generator/package.json index a240d5d43cde..6c579d7680c7 100644 --- a/packages/entity-generator/package.json +++ b/packages/entity-generator/package.json @@ -1,6 +1,6 @@ { "name": "@mikro-orm/entity-generator", - "version": "4.0.5", + "version": "4.0.6", "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -47,11 +47,11 @@ "access": "public" }, "dependencies": { - "@mikro-orm/knex": "^4.0.5", + "@mikro-orm/knex": "^4.0.6", "fs-extra": "^9.0.1" }, "devDependencies": { - "@mikro-orm/core": "^4.0.5" + "@mikro-orm/core": "^4.0.6" }, "peerDependencies": { "@mikro-orm/core": "^4.0.0" diff --git a/packages/knex/CHANGELOG.md b/packages/knex/CHANGELOG.md index a7b1e7255688..448ae57d92e7 100644 --- a/packages/knex/CHANGELOG.md +++ b/packages/knex/CHANGELOG.md @@ -3,6 +3,20 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.6](https://github.com/mikro-orm/mikro-orm/compare/v4.0.5...v4.0.6) (2020-09-22) + + +### Bug Fixes + +* **query-builder:** do not select 1:1 owner when auto-joining ([86c3032](https://github.com/mikro-orm/mikro-orm/commit/86c303229c2ac7b77d245000f64562c0cc529320)), closes [#858](https://github.com/mikro-orm/mikro-orm/issues/858) +* **query-builder:** fix auto-joining of 1:m PKs ([920995f](https://github.com/mikro-orm/mikro-orm/commit/920995f94070ff242b297d2837d83c7d9a9cb776)), closes [#857](https://github.com/mikro-orm/mikro-orm/issues/857) +* **query-builder:** fix count query with auto-joining of 1:1 ([9b8056c](https://github.com/mikro-orm/mikro-orm/commit/9b8056c7440b836d22c8175ba90adf70fc3b052e)), closes [#858](https://github.com/mikro-orm/mikro-orm/issues/858) +* **query-builder:** wrap nested array conditions with `$in` operator ([939989a](https://github.com/mikro-orm/mikro-orm/commit/939989add4f670deefe44f5a7faedb9b64155ba5)), closes [#860](https://github.com/mikro-orm/mikro-orm/issues/860) + + + + + ## [4.0.5](https://github.com/mikro-orm/mikro-orm/compare/v4.0.4...v4.0.5) (2020-09-21) diff --git a/packages/knex/package.json b/packages/knex/package.json index d6f4a829c825..88048458d630 100644 --- a/packages/knex/package.json +++ b/packages/knex/package.json @@ -1,6 +1,6 @@ { "name": "@mikro-orm/knex", - "version": "4.0.5", + "version": "4.0.6", "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -51,7 +51,7 @@ "knex": "^0.21.1" }, "devDependencies": { - "@mikro-orm/core": "^4.0.5" + "@mikro-orm/core": "^4.0.6" }, "peerDependencies": { "@mikro-orm/core": "^4.0.0", diff --git a/packages/knex/src/query/QueryBuilder.ts b/packages/knex/src/query/QueryBuilder.ts index d238a98505b8..bfb49c80e38c 100644 --- a/packages/knex/src/query/QueryBuilder.ts +++ b/packages/knex/src/query/QueryBuilder.ts @@ -60,6 +60,10 @@ export class QueryBuilder = AnyEntity> { } addSelect(fields: string | string[]): this { + if (this.type && this.type !== QueryType.SELECT) { + return this; + } + return this.select([...Utils.asArray(this._fields), ...Utils.asArray(fields)]); } diff --git a/packages/knex/src/query/QueryBuilderHelper.ts b/packages/knex/src/query/QueryBuilderHelper.ts index 47d09d7d1432..fc637e19ad84 100644 --- a/packages/knex/src/query/QueryBuilderHelper.ts +++ b/packages/knex/src/query/QueryBuilderHelper.ts @@ -311,11 +311,6 @@ export class QueryBuilderHelper { const replacement = this.getOperatorReplacement(op, value); const fields = Utils.splitPrimaryKeys(key); - if (key === op) { // substitute top level operators with PK - const meta = this.metadata.find(this.entityName)!; - key = meta.properties[meta.primaryKeys[0]].fieldNames[0]; - } - if (fields.length > 1 && Array.isArray(value[op]) && !value[op].every((v: unknown) => Array.isArray(v))) { value[op] = this.knex.raw(`(${fields.map(() => '?').join(', ')})`, value[op]); } diff --git a/packages/knex/src/query/ScalarCriteriaNode.ts b/packages/knex/src/query/ScalarCriteriaNode.ts index 41df849fca00..9e15f5ba7af0 100644 --- a/packages/knex/src/query/ScalarCriteriaNode.ts +++ b/packages/knex/src/query/ScalarCriteriaNode.ts @@ -6,16 +6,19 @@ export class ScalarCriteriaNode extends CriteriaNode { process(qb: IQueryBuilder, alias?: string): any { if (this.shouldJoin()) { - const nestedAlias = qb.getAliasForJoinPath(this.getPath()) || qb.getNextAlias(); + const path = this.getPath(); + const parentPath = this.parent ? this.parent.getPath() : path; + const nestedAlias = qb.getAliasForJoinPath(path) || qb.getNextAlias(); const field = `${alias}.${this.prop!.name}`; if (this.prop!.reference === ReferenceType.MANY_TO_MANY) { - qb.join(field, nestedAlias, undefined, 'pivotJoin', this.getPath()); + qb.join(field, nestedAlias, undefined, 'pivotJoin', path); } else { - qb.join(field, nestedAlias, undefined, 'leftJoin', this.getPath()); + qb.join(field, nestedAlias, undefined, 'leftJoin', path); } - if (this.prop!.reference === ReferenceType.ONE_TO_ONE) { + // select the owner as virtual property when joining from 1:1 inverse side, but only if the parent is root entity + if (this.prop!.reference === ReferenceType.ONE_TO_ONE && !parentPath.includes('.')) { qb.addSelect(field); } } @@ -24,15 +27,16 @@ export class ScalarCriteriaNode extends CriteriaNode { } shouldJoin(): boolean { - if (!this.parent || !this.prop || [ReferenceType.SCALAR, ReferenceType.ONE_TO_MANY].includes(this.prop.reference)) { + if (!this.parent || !this.prop) { return false; } - if (this.prop.reference === ReferenceType.ONE_TO_ONE) { - return !this.prop.owner; + switch (this.prop.reference) { + case ReferenceType.ONE_TO_MANY: return true; + case ReferenceType.MANY_TO_MANY: return true; + case ReferenceType.ONE_TO_ONE: return !this.prop.owner; + default: return false; // SCALAR, MANY_TO_ONE } - - return this.prop.reference === ReferenceType.MANY_TO_MANY; } } diff --git a/packages/mariadb/CHANGELOG.md b/packages/mariadb/CHANGELOG.md index a33018106222..5763769774af 100644 --- a/packages/mariadb/CHANGELOG.md +++ b/packages/mariadb/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.6](https://github.com/mikro-orm/mikro-orm/compare/v4.0.5...v4.0.6) (2020-09-22) + +**Note:** Version bump only for package @mikro-orm/mariadb + + + + + ## [4.0.5](https://github.com/mikro-orm/mikro-orm/compare/v4.0.4...v4.0.5) (2020-09-21) **Note:** Version bump only for package @mikro-orm/mariadb diff --git a/packages/mariadb/package.json b/packages/mariadb/package.json index 54b2e5ca6a09..e00efd4f7c24 100644 --- a/packages/mariadb/package.json +++ b/packages/mariadb/package.json @@ -1,6 +1,6 @@ { "name": "@mikro-orm/mariadb", - "version": "4.0.5", + "version": "4.0.6", "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -47,11 +47,11 @@ "access": "public" }, "dependencies": { - "@mikro-orm/mysql-base": "^4.0.5", + "@mikro-orm/mysql-base": "^4.0.6", "mariadb": "^2.4.0" }, "devDependencies": { - "@mikro-orm/core": "^4.0.5" + "@mikro-orm/core": "^4.0.6" }, "peerDependencies": { "@mikro-orm/core": "^4.0.0" diff --git a/packages/migrations/CHANGELOG.md b/packages/migrations/CHANGELOG.md index 1cff8fd8dc19..077a7bc4a876 100644 --- a/packages/migrations/CHANGELOG.md +++ b/packages/migrations/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.6](https://github.com/mikro-orm/mikro-orm/compare/v4.0.5...v4.0.6) (2020-09-22) + + +### Bug Fixes + +* **migrations:** migrate only one version down with explicit tx ([50567dd](https://github.com/mikro-orm/mikro-orm/commit/50567ddd384ac2b53512925cade28e8debbb9f3b)), closes [#855](https://github.com/mikro-orm/mikro-orm/issues/855) + + + + + ## [4.0.5](https://github.com/mikro-orm/mikro-orm/compare/v4.0.4...v4.0.5) (2020-09-21) **Note:** Version bump only for package @mikro-orm/migrations diff --git a/packages/migrations/package.json b/packages/migrations/package.json index 56e7202496a8..fa3c0b65a533 100644 --- a/packages/migrations/package.json +++ b/packages/migrations/package.json @@ -1,6 +1,6 @@ { "name": "@mikro-orm/migrations", - "version": "4.0.5", + "version": "4.0.6", "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -47,13 +47,13 @@ "access": "public" }, "dependencies": { - "@mikro-orm/knex": "^4.0.5", + "@mikro-orm/knex": "^4.0.6", "@types/umzug": "^2.2.3", "fs-extra": "^9.0.1", "umzug": "^2.3.0" }, "devDependencies": { - "@mikro-orm/core": "^4.0.5" + "@mikro-orm/core": "^4.0.6" }, "peerDependencies": { "@mikro-orm/core": "^4.0.0" diff --git a/packages/migrations/src/Migrator.ts b/packages/migrations/src/Migrator.ts index d94a36d134fd..e28be7966e8a 100644 --- a/packages/migrations/src/Migrator.ts +++ b/packages/migrations/src/Migrator.ts @@ -134,12 +134,12 @@ export class Migrator { return lines; } - private prefix(options?: T): T { + private prefix(options?: T): T { if (Utils.isString(options) || Array.isArray(options)) { return Utils.asArray(options).map(m => m.startsWith('Migration') ? m : 'Migration' + m) as T; } - if (!Utils.isObject<{ from?: string; to?: string; migrations?: string[] }>(options)) { + if (!Utils.isObject<{ from?: string; to?: string; migrations?: string[]; transaction?: Transaction }>(options)) { return options as T; } @@ -147,6 +147,10 @@ export class Migrator { options.migrations = options.migrations.map(m => this.prefix(m)); } + if (options.transaction) { + delete options.transaction; + } + ['from', 'to'].filter(k => options[k]).forEach(k => options[k] = this.prefix(options[k])); return options as T; diff --git a/packages/mikro-orm/CHANGELOG.md b/packages/mikro-orm/CHANGELOG.md index 95953c96b918..29d2cb546b1e 100644 --- a/packages/mikro-orm/CHANGELOG.md +++ b/packages/mikro-orm/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.6](https://github.com/mikro-orm/mikro-orm/compare/v4.0.5...v4.0.6) (2020-09-22) + +**Note:** Version bump only for package mikro-orm + + + + + ## [4.0.5](https://github.com/mikro-orm/mikro-orm/compare/v4.0.4...v4.0.5) (2020-09-21) **Note:** Version bump only for package mikro-orm diff --git a/packages/mikro-orm/package.json b/packages/mikro-orm/package.json index 1a786b43afa9..4e0d63946a33 100644 --- a/packages/mikro-orm/package.json +++ b/packages/mikro-orm/package.json @@ -1,6 +1,6 @@ { "name": "mikro-orm", - "version": "4.0.5", + "version": "4.0.6", "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -47,11 +47,11 @@ "access": "public" }, "dependencies": { - "@mikro-orm/cli": "^4.0.5", - "@mikro-orm/core": "^4.0.5", - "@mikro-orm/entity-generator": "^4.0.5", - "@mikro-orm/migrations": "^4.0.5", - "@mikro-orm/reflection": "^4.0.5" + "@mikro-orm/cli": "^4.0.6", + "@mikro-orm/core": "^4.0.6", + "@mikro-orm/entity-generator": "^4.0.6", + "@mikro-orm/migrations": "^4.0.6", + "@mikro-orm/reflection": "^4.0.6" }, "peerDependencies": { "@mikro-orm/mariadb": "^4.0.0", diff --git a/packages/mongodb/CHANGELOG.md b/packages/mongodb/CHANGELOG.md index 4e1bdc137d26..98e2ea58f172 100644 --- a/packages/mongodb/CHANGELOG.md +++ b/packages/mongodb/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.6](https://github.com/mikro-orm/mikro-orm/compare/v4.0.5...v4.0.6) (2020-09-22) + +**Note:** Version bump only for package @mikro-orm/mongodb + + + + + ## [4.0.5](https://github.com/mikro-orm/mikro-orm/compare/v4.0.4...v4.0.5) (2020-09-21) **Note:** Version bump only for package @mikro-orm/mongodb diff --git a/packages/mongodb/package.json b/packages/mongodb/package.json index 271702b384f0..47616e1d17ad 100644 --- a/packages/mongodb/package.json +++ b/packages/mongodb/package.json @@ -1,6 +1,6 @@ { "name": "@mikro-orm/mongodb", - "version": "4.0.5", + "version": "4.0.6", "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -51,7 +51,7 @@ "mongodb": "^3.6.0" }, "devDependencies": { - "@mikro-orm/core": "^4.0.5" + "@mikro-orm/core": "^4.0.6" }, "peerDependencies": { "@mikro-orm/core": "^4.0.0" diff --git a/packages/mysql-base/CHANGELOG.md b/packages/mysql-base/CHANGELOG.md index 384bfa33b736..f1d7b258b39b 100644 --- a/packages/mysql-base/CHANGELOG.md +++ b/packages/mysql-base/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.6](https://github.com/mikro-orm/mikro-orm/compare/v4.0.5...v4.0.6) (2020-09-22) + +**Note:** Version bump only for package @mikro-orm/mysql-base + + + + + ## [4.0.5](https://github.com/mikro-orm/mikro-orm/compare/v4.0.4...v4.0.5) (2020-09-21) **Note:** Version bump only for package @mikro-orm/mysql-base diff --git a/packages/mysql-base/package.json b/packages/mysql-base/package.json index a92eaada7d29..0af3eb3c771c 100644 --- a/packages/mysql-base/package.json +++ b/packages/mysql-base/package.json @@ -1,6 +1,6 @@ { "name": "@mikro-orm/mysql-base", - "version": "4.0.5", + "version": "4.0.6", "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -47,10 +47,10 @@ "access": "public" }, "dependencies": { - "@mikro-orm/knex": "^4.0.5" + "@mikro-orm/knex": "^4.0.6" }, "devDependencies": { - "@mikro-orm/core": "^4.0.5" + "@mikro-orm/core": "^4.0.6" }, "peerDependencies": { "@mikro-orm/core": "^4.0.0", diff --git a/packages/mysql/CHANGELOG.md b/packages/mysql/CHANGELOG.md index 4660672a5c55..6d8112957007 100644 --- a/packages/mysql/CHANGELOG.md +++ b/packages/mysql/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.6](https://github.com/mikro-orm/mikro-orm/compare/v4.0.5...v4.0.6) (2020-09-22) + +**Note:** Version bump only for package @mikro-orm/mysql + + + + + ## [4.0.5](https://github.com/mikro-orm/mikro-orm/compare/v4.0.4...v4.0.5) (2020-09-21) **Note:** Version bump only for package @mikro-orm/mysql diff --git a/packages/mysql/package.json b/packages/mysql/package.json index 1fbac10db460..b076f1e491a4 100644 --- a/packages/mysql/package.json +++ b/packages/mysql/package.json @@ -1,6 +1,6 @@ { "name": "@mikro-orm/mysql", - "version": "4.0.5", + "version": "4.0.6", "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -47,11 +47,11 @@ "access": "public" }, "dependencies": { - "@mikro-orm/mysql-base": "^4.0.5", - "mysql2": "sidorares/node-mysql2#master" + "@mikro-orm/mysql-base": "^4.0.6", + "mysql2": "^2.2.5" }, "devDependencies": { - "@mikro-orm/core": "^4.0.5" + "@mikro-orm/core": "^4.0.6" }, "peerDependencies": { "@mikro-orm/core": "^4.0.0" diff --git a/packages/postgresql/CHANGELOG.md b/packages/postgresql/CHANGELOG.md index 0e75501eb190..972396a66b38 100644 --- a/packages/postgresql/CHANGELOG.md +++ b/packages/postgresql/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.6](https://github.com/mikro-orm/mikro-orm/compare/v4.0.5...v4.0.6) (2020-09-22) + +**Note:** Version bump only for package @mikro-orm/postgresql + + + + + ## [4.0.5](https://github.com/mikro-orm/mikro-orm/compare/v4.0.4...v4.0.5) (2020-09-21) diff --git a/packages/postgresql/package.json b/packages/postgresql/package.json index c083bead7e17..46e4e33a1c35 100644 --- a/packages/postgresql/package.json +++ b/packages/postgresql/package.json @@ -1,6 +1,6 @@ { "name": "@mikro-orm/postgresql", - "version": "4.0.5", + "version": "4.0.6", "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -47,11 +47,11 @@ "access": "public" }, "dependencies": { - "@mikro-orm/knex": "^4.0.5", + "@mikro-orm/knex": "^4.0.6", "pg": "^8.2.1" }, "devDependencies": { - "@mikro-orm/core": "^4.0.5" + "@mikro-orm/core": "^4.0.6" }, "peerDependencies": { "@mikro-orm/core": "^4.0.0" diff --git a/packages/reflection/CHANGELOG.md b/packages/reflection/CHANGELOG.md index 7535b8a11159..e702dab8a8b6 100644 --- a/packages/reflection/CHANGELOG.md +++ b/packages/reflection/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.6](https://github.com/mikro-orm/mikro-orm/compare/v4.0.5...v4.0.6) (2020-09-22) + +**Note:** Version bump only for package @mikro-orm/reflection + + + + + ## [4.0.5](https://github.com/mikro-orm/mikro-orm/compare/v4.0.4...v4.0.5) (2020-09-21) **Note:** Version bump only for package @mikro-orm/reflection diff --git a/packages/reflection/package.json b/packages/reflection/package.json index 1c6195918d2f..4287a7bdfa36 100644 --- a/packages/reflection/package.json +++ b/packages/reflection/package.json @@ -1,6 +1,6 @@ { "name": "@mikro-orm/reflection", - "version": "4.0.5", + "version": "4.0.6", "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -51,7 +51,7 @@ "ts-morph": "^8.0.0" }, "devDependencies": { - "@mikro-orm/core": "^4.0.5" + "@mikro-orm/core": "^4.0.6" }, "peerDependencies": { "@mikro-orm/core": "^4.0.0" diff --git a/packages/sqlite/CHANGELOG.md b/packages/sqlite/CHANGELOG.md index 2c9cfa66e638..2d2f7076656f 100644 --- a/packages/sqlite/CHANGELOG.md +++ b/packages/sqlite/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.0.6](https://github.com/mikro-orm/mikro-orm/compare/v4.0.5...v4.0.6) (2020-09-22) + +**Note:** Version bump only for package @mikro-orm/sqlite + + + + + ## [4.0.5](https://github.com/mikro-orm/mikro-orm/compare/v4.0.4...v4.0.5) (2020-09-21) diff --git a/packages/sqlite/package.json b/packages/sqlite/package.json index 86aa971c8f8b..c06b30f086e6 100644 --- a/packages/sqlite/package.json +++ b/packages/sqlite/package.json @@ -1,6 +1,6 @@ { "name": "@mikro-orm/sqlite", - "version": "4.0.5", + "version": "4.0.6", "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.", "main": "dist/index.js", "typings": "dist/index.d.ts", @@ -47,12 +47,12 @@ "access": "public" }, "dependencies": { - "@mikro-orm/knex": "^4.0.5", + "@mikro-orm/knex": "^4.0.6", "fs-extra": "^9.0.1", "sqlite3": "^4.2.0" }, "devDependencies": { - "@mikro-orm/core": "^4.0.5" + "@mikro-orm/core": "^4.0.6" }, "peerDependencies": { "@mikro-orm/core": "^4.0.0" diff --git a/tests/EntityGenerator.test.ts b/tests/EntityGenerator.test.ts index e2f5fb92b624..2c4ff9c793ac 100644 --- a/tests/EntityGenerator.test.ts +++ b/tests/EntityGenerator.test.ts @@ -6,7 +6,7 @@ import { initORMMySql, initORMPostgreSql, initORMSqlite } from './bootstrap'; describe('EntityGenerator', () => { test('generate entities from schema [mysql]', async () => { - const orm = await initORMMySql(); + const orm = await initORMMySql('mysql', {}, true); const generator = orm.getEntityGenerator(); const dump = await generator.generate({ save: true, baseDir: './temp/entities' }); expect(dump).toMatchSnapshot('mysql-entity-dump'); diff --git a/tests/Migrator.test.ts b/tests/Migrator.test.ts index 43236769404f..a9a571e997b5 100644 --- a/tests/Migrator.test.ts +++ b/tests/Migrator.test.ts @@ -3,7 +3,7 @@ import umzug from 'umzug'; import { Logger, MikroORM } from '@mikro-orm/core'; import { Migration, MigrationStorage, Migrator } from '@mikro-orm/migrations'; import { MySqlDriver } from '@mikro-orm/mysql'; -import { remove, writeFile } from 'fs-extra'; +import { remove } from 'fs-extra'; import { initORMMySql } from './bootstrap'; class MigrationTest1 extends Migration { @@ -120,7 +120,9 @@ describe('Migrator', () => { await migrator.up(); expect(upMock).toBeCalledTimes(1); expect(downMock).toBeCalledTimes(0); - await migrator.down(); + await orm.em.begin(); + await migrator.down({ transaction: orm.em.getTransactionContext() }); + await orm.em.commit(); expect(upMock).toBeCalledTimes(1); expect(downMock).toBeCalledTimes(1); upMock.mockRestore(); @@ -224,20 +226,34 @@ describe('Migrator', () => { const migrator = new Migrator(orm.em); const path = process.cwd() + '/temp/migrations'; - const migration = await migrator.createMigration(path, true); - const migratorMock = jest.spyOn(Migration.prototype, 'down'); - migratorMock.mockImplementation(async () => void 0); + // @ts-ignore + migrator.options.disableForeignKeys = false; + + const dateMock = jest.spyOn(Date.prototype, 'toISOString'); + dateMock.mockReturnValueOnce('2020-09-22T10:00:01.000Z'); + dateMock.mockReturnValueOnce('2020-09-22T10:00:02.000Z'); + const migration1 = await migrator.createMigration(path, true); + const migration2 = await migrator.createMigration(path, true); + const migrationMock = jest.spyOn(Migration.prototype, 'down'); + migrationMock.mockImplementation(async () => void 0); const mock = jest.fn(); const logger = new Logger(mock, ['query']); Object.assign(orm.config, { logger }); await orm.em.transactional(async em => { - await migrator.up({ transaction: em.getTransactionContext() }); - await migrator.down({ transaction: em.getTransactionContext() }); + const ret1 = await migrator.up({ transaction: em.getTransactionContext() }); + const ret2 = await migrator.down({ transaction: em.getTransactionContext() }); + const ret3 = await migrator.down({ transaction: em.getTransactionContext() }); + const ret4 = await migrator.down({ transaction: em.getTransactionContext() }); + expect(ret1).toHaveLength(2); + expect(ret2).toHaveLength(1); + expect(ret3).toHaveLength(1); + expect(ret4).toHaveLength(0); }); - await remove(path + '/' + migration.fileName); + await remove(path + '/' + migration1.fileName); + await remove(path + '/' + migration2.fileName); const calls = mock.mock.calls.map(call => { return call[0] .replace(/ \[took \d+ ms]/, '') @@ -257,7 +273,6 @@ describe('Migrator', () => { const path = process.cwd() + '/temp/migrations'; const migration = await migrator.createMigration(path, true); - await writeFile(path + '/' + migration.fileName, migration.code.replace(`'mikro-orm'`, `'@mikro-orm/migrations'`)); const migratorMock = jest.spyOn(Migration.prototype, 'down'); migratorMock.mockImplementation(async () => void 0); diff --git a/tests/QueryBuilder.test.ts b/tests/QueryBuilder.test.ts index 613666621a2d..f4709a314249 100644 --- a/tests/QueryBuilder.test.ts +++ b/tests/QueryBuilder.test.ts @@ -7,6 +7,7 @@ import { Address2, Author2, Book2, BookTag2, Car2, CarOwner2, Configuration2, Fo import { initORMMySql } from './bootstrap'; import { BaseEntity2 } from './entities-sql/BaseEntity2'; import { performance } from 'perf_hooks'; +import { BaseEntity22 } from './entities-sql/BaseEntity22'; describe('QueryBuilder', () => { @@ -1579,7 +1580,7 @@ describe('QueryBuilder', () => { test('pg array operators', async () => { const pg = await MikroORM.init({ - entities: [Author2, Address2, Book2, BookTag2, Publisher2, Test2, BaseEntity2, Configuration2], + entities: [Author2, Address2, Book2, BookTag2, Publisher2, Test2, FooBar2, FooBaz2, BaseEntity2, BaseEntity22, Configuration2], dbName: `mikro_orm_test`, type: 'postgresql', }); @@ -1653,6 +1654,66 @@ describe('QueryBuilder', () => { expect(sql7).toBe('select `e0`.* from `test2` as `e0` where `e0`.`book_uuid_pk` in (?)'); }); + test('query by 1:m PK (GH issue 857)', async () => { + const sql0 = orm.em.createQueryBuilder(Author2).select('*').where({ books: '123' }).getQuery(); + expect(sql0).toBe('select `e0`.* from `author2` as `e0` left join `book2` as `e1` on `e0`.`id` = `e1`.`author_id` where `e1`.`uuid_pk` = ?'); + const expected = 'select `e0`.* from `author2` as `e0` left join `book2` as `e1` on `e0`.`id` = `e1`.`author_id` where `e1`.`uuid_pk` in (?)'; + const sql1 = orm.em.createQueryBuilder(Author2).where({ books: [123] }).getQuery(); + expect(sql1).toBe(expected); + const sql2 = orm.em.createQueryBuilder(Author2).where({ books: { uuid: [123] } }).getQuery(); + expect(sql2).toBe(expected); + const sql3 = orm.em.createQueryBuilder(Author2).where({ books: { uuid: { $in: [123] } } }).getQuery(); + expect(sql3).toBe(expected); + const sql4 = orm.em.createQueryBuilder(Author2).where({ $and: [{ books: { uuid: { $in: [123] } } }] }).getQuery(); + expect(sql4).toBe(expected); + const sql5 = orm.em.createQueryBuilder(Author2).where({ $and: [{ books: [123] }] }).getQuery(); + expect(sql5).toBe(expected); + const sql6 = orm.em.createQueryBuilder(Author2).where({ $and: [{ books: { uuid: [123] } }] }).getQuery(); + expect(sql6).toBe(expected); + }); + + test('count query with auto-joining (GH issue 858)', async () => { + // m:1 -> 1:1 inverse -> PK + const sql1 = orm.em.createQueryBuilder(Author2).count().where({ favouriteBook: { test: { id: 1 } } }).getQuery(); + expect(sql1).toBe('select count(`e0`.`id`) as `count` ' + + 'from `author2` as `e0` ' + + 'left join `book2` as `e1` on `e0`.`favourite_book_uuid_pk` = `e1`.`uuid_pk` ' + + 'left join `test2` as `e2` on `e1`.`uuid_pk` = `e2`.`book_uuid_pk` ' + + 'where `e2`.`id` = ?'); + + const sql2 = orm.em.createQueryBuilder(Author2).select('*').where({ favouriteBook: { test: { id: 1 } } }).getQuery(); + expect(sql2).toBe('select `e0`.* ' + + 'from `author2` as `e0` ' + + 'left join `book2` as `e1` on `e0`.`favourite_book_uuid_pk` = `e1`.`uuid_pk` ' + + 'left join `test2` as `e2` on `e1`.`uuid_pk` = `e2`.`book_uuid_pk` ' + + 'where `e2`.`id` = ?'); + + const sql3 = orm.em.createQueryBuilder(Book2).count().where({ test: { id: 1 } }).getQuery(); + expect(sql3).toBe('select count(`e0`.`uuid_pk`) as `count` ' + + 'from `book2` as `e0` ' + + 'left join `test2` as `e1` on `e0`.`uuid_pk` = `e1`.`book_uuid_pk` ' + + 'where `e1`.`id` = ?'); + + const sql4 = orm.em.createQueryBuilder(Book2).select('*').where({ test: { id: 1 } }).getQuery(); + expect(sql4).toBe('select `e0`.*, `e1`.`id` as `test_id`, `e0`.price * 1.19 as `price_taxed` ' + + 'from `book2` as `e0` ' + + 'left join `test2` as `e1` on `e0`.`uuid_pk` = `e1`.`book_uuid_pk` ' + + 'where `e1`.`id` = ?'); + }); + + test('deeply nested array condition without operator (GH issue 860)', async () => { + // 1:1 inverse -> m:n inverse -> [PK] + let expected = 'select `e0`.* from `foo_baz2` as `e0` left join `foo_bar2` as `e1` on `e0`.`id` = `e1`.`baz_id` left join `test2_bars` as `e2` on `e1`.`id` = `e2`.`foo_bar2_id` where `e2`.`test2_id` in (?, ?, ?)'; + const sql1 = orm.em.createQueryBuilder(FooBaz2).where({ bar: { tests: { $in: [1, 2, 3] } } }).getQuery(); + expect(sql1).toBe(expected); + const sql2 = orm.em.createQueryBuilder(FooBaz2).where({ bar: { tests: [1, 2, 3] } }).getQuery(); + expect(sql2).toBe(expected); + + expected = 'select `e0`.* from `foo_baz2` as `e0` left join `foo_bar2` as `e1` on `e0`.`id` = `e1`.`baz_id` left join `test2_bars` as `e2` on `e1`.`id` = `e2`.`foo_bar2_id` where `e2`.`test2_id` = ?'; + const sql3 = orm.em.createQueryBuilder(FooBaz2).where({ bar: { tests: 3 } }).getQuery(); + expect(sql3).toBe(expected); + }); + afterAll(async () => orm.close(true)); }); diff --git a/tests/SchemaGenerator.test.ts b/tests/SchemaGenerator.test.ts index 090013321a63..230f2666e2a6 100644 --- a/tests/SchemaGenerator.test.ts +++ b/tests/SchemaGenerator.test.ts @@ -1,15 +1,16 @@ import { BASE_DIR, initORMMySql, initORMPostgreSql, initORMSqlite, initORMSqlite2 } from './bootstrap'; import { EntitySchema, ReferenceType, Utils, MikroORM } from '@mikro-orm/core'; import { SchemaGenerator, EntityManager } from '@mikro-orm/knex'; -import { FooBar2, FooBaz2 } from './entities-sql'; +import { Address2, Author2, Book2, BookTag2, Configuration2, FooBar2, FooBaz2, Publisher2, Test2 } from './entities-sql'; import { BaseEntity22 } from './entities-sql/BaseEntity22'; +import { BaseEntity2 } from './entities-sql/BaseEntity2'; describe('SchemaGenerator', () => { test('create/drop database [mysql]', async () => { const dbName = `mikro_orm_test_${Date.now()}`; const orm = await MikroORM.init({ - entities: [FooBar2, FooBaz2, BaseEntity22], + entities: [FooBar2, FooBaz2, Test2, Book2, Author2, Configuration2, Publisher2, BookTag2, Address2, BaseEntity2, BaseEntity22], dbName, port: 3307, baseDir: BASE_DIR, @@ -25,7 +26,7 @@ describe('SchemaGenerator', () => { test('create schema also creates the database if not exists [mysql]', async () => { const dbName = `mikro_orm_test_${Date.now()}`; const orm = await MikroORM.init({ - entities: [FooBar2, FooBaz2, BaseEntity22], + entities: [FooBar2, FooBaz2, Test2, Book2, Author2, Configuration2, Publisher2, BookTag2, Address2, BaseEntity2, BaseEntity22], dbName, port: 3307, baseDir: BASE_DIR, @@ -44,7 +45,7 @@ describe('SchemaGenerator', () => { test('create/drop database [mariadb]', async () => { const dbName = `mikro_orm_test_${Date.now()}`; const orm = await MikroORM.init({ - entities: [FooBar2, FooBaz2, BaseEntity22], + entities: [FooBar2, FooBaz2, Test2, Book2, Author2, Configuration2, Publisher2, BookTag2, Address2, BaseEntity2, BaseEntity22], dbName, port: 3307, baseDir: BASE_DIR, @@ -61,7 +62,7 @@ describe('SchemaGenerator', () => { test('create schema also creates the database if not exists [mariadb]', async () => { const dbName = `mikro_orm_test_${Date.now()}`; const orm = await MikroORM.init({ - entities: [FooBar2, FooBaz2, BaseEntity22], + entities: [FooBar2, FooBaz2, Test2, Book2, Author2, Configuration2, Publisher2, BookTag2, Address2, BaseEntity2, BaseEntity22], dbName, port: 3307, baseDir: BASE_DIR, @@ -378,7 +379,7 @@ describe('SchemaGenerator', () => { test('create/drop database [postgresql]', async () => { const dbName = `mikro_orm_test_${Date.now()}`; const orm = await MikroORM.init({ - entities: [FooBar2, FooBaz2, BaseEntity22], + entities: [FooBar2, FooBaz2, Test2, Book2, Author2, Configuration2, Publisher2, BookTag2, Address2, BaseEntity2, BaseEntity22], dbName, baseDir: BASE_DIR, type: 'postgresql', @@ -393,7 +394,7 @@ describe('SchemaGenerator', () => { test('create schema also creates the database if not exists [postgresql]', async () => { const dbName = `mikro_orm_test_${Date.now()}`; const orm = await MikroORM.init({ - entities: [FooBar2, FooBaz2, BaseEntity22], + entities: [FooBar2, FooBaz2, Test2, Book2, Author2, Configuration2, Publisher2, BookTag2, Address2, BaseEntity2, BaseEntity22], dbName, baseDir: BASE_DIR, type: 'postgresql', diff --git a/tests/__snapshots__/EntityGenerator.test.ts.snap b/tests/__snapshots__/EntityGenerator.test.ts.snap index ae6110df4b8e..2cf51a3f22b9 100644 --- a/tests/__snapshots__/EntityGenerator.test.ts.snap +++ b/tests/__snapshots__/EntityGenerator.test.ts.snap @@ -437,6 +437,21 @@ export class Test2 { @Property({ fieldName: 'foo___baz', nullable: true }) fooBaz?: number; +} +", + "import { Cascade, Entity, ManyToOne } from '@mikro-orm/core'; +import { FooBar2 } from './FooBar2'; +import { Test2 } from './Test2'; + +@Entity() +export class Test2Bars { + + @ManyToOne({ entity: () => Test2, cascade: [Cascade.ALL], primary: true, index: 'test2_bars_test2_id_index' }) + test2!: Test2; + + @ManyToOne({ entity: () => FooBar2, cascade: [Cascade.ALL], primary: true, index: 'test2_bars_foo_bar2_id_index' }) + fooBar2!: FooBar2; + } ", "import { Entity, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'; @@ -842,6 +857,21 @@ export class Test2 { @Property({ columnType: 'polygon', nullable: true }) path?: string; +} +", + "import { Cascade, Entity, ManyToOne } from '@mikro-orm/core'; +import { FooBar2 } from './FooBar2'; +import { Test2 } from './Test2'; + +@Entity() +export class Test2Bars { + + @ManyToOne({ entity: () => Test2, cascade: [Cascade.ALL], primary: true }) + test2!: Test2; + + @ManyToOne({ entity: () => FooBar2, cascade: [Cascade.ALL], primary: true }) + fooBar2!: FooBar2; + } ", ] diff --git a/tests/__snapshots__/Migrator.test.ts.snap b/tests/__snapshots__/Migrator.test.ts.snap index f24f2f2deea5..4bb3a120f394 100644 --- a/tests/__snapshots__/Migrator.test.ts.snap +++ b/tests/__snapshots__/Migrator.test.ts.snap @@ -94,6 +94,11 @@ export class Migration20191013214813 extends Migration { this.addSql('alter table \`publisher2_tests\` add index \`publisher2_tests_publisher2_id_index\`(\`publisher2_id\`);'); this.addSql('alter table \`publisher2_tests\` add index \`publisher2_tests_test2_id_index\`(\`test2_id\`);'); + this.addSql('create table \`test2_bars\` (\`test2_id\` int(11) unsigned not null, \`foo_bar2_id\` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB;'); + this.addSql('alter table \`test2_bars\` add index \`test2_bars_test2_id_index\`(\`test2_id\`);'); + this.addSql('alter table \`test2_bars\` add index \`test2_bars_foo_bar2_id_index\`(\`foo_bar2_id\`);'); + this.addSql('alter table \`test2_bars\` add primary key \`test2_bars_pkey\`(\`test2_id\`, \`foo_bar2_id\`);'); + this.addSql('create table \`book2_tags\` (\`order\` int unsigned not null auto_increment primary key, \`book2_uuid_pk\` varchar(36) not null, \`book_tag2_id\` bigint unsigned not null) default character set utf8mb4 engine = InnoDB;'); this.addSql('alter table \`book2_tags\` add index \`book2_tags_book2_uuid_pk_index\`(\`book2_uuid_pk\`);'); this.addSql('alter table \`book2_tags\` add index \`book2_tags_book_tag2_id_index\`(\`book_tag2_id\`);'); @@ -150,6 +155,9 @@ export class Migration20191013214813 extends Migration { this.addSql('alter table \`publisher2_tests\` add constraint \`publisher2_tests_publisher2_id_foreign\` foreign key (\`publisher2_id\`) references \`publisher2\` (\`id\`) on update cascade on delete cascade;'); this.addSql('alter table \`publisher2_tests\` add constraint \`publisher2_tests_test2_id_foreign\` foreign key (\`test2_id\`) references \`test2\` (\`id\`) on update cascade on delete cascade;'); + this.addSql('alter table \`test2_bars\` add constraint \`test2_bars_test2_id_foreign\` foreign key (\`test2_id\`) references \`test2\` (\`id\`) on update cascade on delete cascade;'); + this.addSql('alter table \`test2_bars\` add constraint \`test2_bars_foo_bar2_id_foreign\` foreign key (\`foo_bar2_id\`) references \`foo_bar2\` (\`id\`) on update cascade on delete cascade;'); + this.addSql('alter table \`book2_tags\` add constraint \`book2_tags_book2_uuid_pk_foreign\` foreign key (\`book2_uuid_pk\`) references \`book2\` (\`uuid_pk\`) on update cascade on delete cascade;'); this.addSql('alter table \`book2_tags\` add constraint \`book2_tags_book_tag2_id_foreign\` foreign key (\`book_tag2_id\`) references \`book_tag2\` (\`id\`) on update cascade on delete cascade;'); @@ -252,6 +260,11 @@ export class Migration20191013214813 extends Migration { "alter table \`publisher2_tests\` add index \`publisher2_tests_publisher2_id_index\`(\`publisher2_id\`);", "alter table \`publisher2_tests\` add index \`publisher2_tests_test2_id_index\`(\`test2_id\`);", "", + "create table \`test2_bars\` (\`test2_id\` int(11) unsigned not null, \`foo_bar2_id\` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB;", + "alter table \`test2_bars\` add index \`test2_bars_test2_id_index\`(\`test2_id\`);", + "alter table \`test2_bars\` add index \`test2_bars_foo_bar2_id_index\`(\`foo_bar2_id\`);", + "alter table \`test2_bars\` add primary key \`test2_bars_pkey\`(\`test2_id\`, \`foo_bar2_id\`);", + "", "create table \`book2_tags\` (\`order\` int unsigned not null auto_increment primary key, \`book2_uuid_pk\` varchar(36) not null, \`book_tag2_id\` bigint unsigned not null) default character set utf8mb4 engine = InnoDB;", "alter table \`book2_tags\` add index \`book2_tags_book2_uuid_pk_index\`(\`book2_uuid_pk\`);", "alter table \`book2_tags\` add index \`book2_tags_book_tag2_id_index\`(\`book_tag2_id\`);", @@ -308,6 +321,9 @@ export class Migration20191013214813 extends Migration { "alter table \`publisher2_tests\` add constraint \`publisher2_tests_publisher2_id_foreign\` foreign key (\`publisher2_id\`) references \`publisher2\` (\`id\`) on update cascade on delete cascade;", "alter table \`publisher2_tests\` add constraint \`publisher2_tests_test2_id_foreign\` foreign key (\`test2_id\`) references \`test2\` (\`id\`) on update cascade on delete cascade;", "", + "alter table \`test2_bars\` add constraint \`test2_bars_test2_id_foreign\` foreign key (\`test2_id\`) references \`test2\` (\`id\`) on update cascade on delete cascade;", + "alter table \`test2_bars\` add constraint \`test2_bars_foo_bar2_id_foreign\` foreign key (\`foo_bar2_id\`) references \`foo_bar2\` (\`id\`) on update cascade on delete cascade;", + "", "alter table \`book2_tags\` add constraint \`book2_tags_book2_uuid_pk_foreign\` foreign key (\`book2_uuid_pk\`) references \`book2\` (\`uuid_pk\`) on update cascade on delete cascade;", "alter table \`book2_tags\` add constraint \`book2_tags_book_tag2_id_foreign\` foreign key (\`book_tag2_id\`) references \`book_tag2\` (\`id\`) on update cascade on delete cascade;", "", @@ -565,12 +581,27 @@ Array [ "select 1 (via write connection '127.0.0.1')", "release savepointtrx_xx (via write connection '127.0.0.1')", "insert into \`mikro_orm_migrations\` (\`name\`) values (?) (via write connection '127.0.0.1')", + "select * from \`mikro_orm_migrations\` order by \`id\` asc (via write connection '127.0.0.1')", + "savepointtrx_xx (via write connection '127.0.0.1')", + "select 1 (via write connection '127.0.0.1')", + "release savepointtrx_xx (via write connection '127.0.0.1')", + "insert into \`mikro_orm_migrations\` (\`name\`) values (?) (via write connection '127.0.0.1')", "select table_name as table_name from information_schema.tables where table_type = 'BASE TABLE' and table_schema = schema() (via write connection '127.0.0.1')", "select * from \`mikro_orm_migrations\` order by \`id\` asc (via write connection '127.0.0.1')", "select * from \`mikro_orm_migrations\` order by \`id\` asc (via write connection '127.0.0.1')", + "select * from \`mikro_orm_migrations\` order by \`id\` asc (via write connection '127.0.0.1')", "savepointtrx_xx (via write connection '127.0.0.1')", "release savepointtrx_xx (via write connection '127.0.0.1')", "delete from \`mikro_orm_migrations\` where \`name\` = ? (via write connection '127.0.0.1')", + "select table_name as table_name from information_schema.tables where table_type = 'BASE TABLE' and table_schema = schema() (via write connection '127.0.0.1')", + "select * from \`mikro_orm_migrations\` order by \`id\` asc (via write connection '127.0.0.1')", + "select * from \`mikro_orm_migrations\` order by \`id\` asc (via write connection '127.0.0.1')", + "select * from \`mikro_orm_migrations\` order by \`id\` asc (via write connection '127.0.0.1')", + "savepointtrx_xx (via write connection '127.0.0.1')", + "release savepointtrx_xx (via write connection '127.0.0.1')", + "delete from \`mikro_orm_migrations\` where \`name\` = ? (via write connection '127.0.0.1')", + "select table_name as table_name from information_schema.tables where table_type = 'BASE TABLE' and table_schema = schema() (via write connection '127.0.0.1')", + "select * from \`mikro_orm_migrations\` order by \`id\` asc (via write connection '127.0.0.1')", "commit (via write connection '127.0.0.1')", ] `; diff --git a/tests/__snapshots__/SchemaGenerator.test.ts.snap b/tests/__snapshots__/SchemaGenerator.test.ts.snap index 3cbf65f42b12..456359798e64 100644 --- a/tests/__snapshots__/SchemaGenerator.test.ts.snap +++ b/tests/__snapshots__/SchemaGenerator.test.ts.snap @@ -74,6 +74,11 @@ create table \`publisher2_tests\` (\`id\` int unsigned not null auto_increment p alter table \`publisher2_tests\` add index \`publisher2_tests_publisher2_id_index\`(\`publisher2_id\`); alter table \`publisher2_tests\` add index \`publisher2_tests_test2_id_index\`(\`test2_id\`); +create table \`test2_bars\` (\`test2_id\` int(11) unsigned not null, \`foo_bar2_id\` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB; +alter table \`test2_bars\` add index \`test2_bars_test2_id_index\`(\`test2_id\`); +alter table \`test2_bars\` add index \`test2_bars_foo_bar2_id_index\`(\`foo_bar2_id\`); +alter table \`test2_bars\` add primary key \`test2_bars_pkey\`(\`test2_id\`, \`foo_bar2_id\`); + create table \`book2_tags\` (\`order\` int unsigned not null auto_increment primary key, \`book2_uuid_pk\` varchar(36) not null, \`book_tag2_id\` bigint unsigned not null) default character set utf8mb4 engine = InnoDB; alter table \`book2_tags\` add index \`book2_tags_book2_uuid_pk_index\`(\`book2_uuid_pk\`); alter table \`book2_tags\` add index \`book2_tags_book_tag2_id_index\`(\`book_tag2_id\`); @@ -130,6 +135,9 @@ alter table \`configuration2\` add constraint \`configuration2_test_id_foreign\` alter table \`publisher2_tests\` add constraint \`publisher2_tests_publisher2_id_foreign\` foreign key (\`publisher2_id\`) references \`publisher2\` (\`id\`) on update cascade on delete cascade; alter table \`publisher2_tests\` add constraint \`publisher2_tests_test2_id_foreign\` foreign key (\`test2_id\`) references \`test2\` (\`id\`) on update cascade on delete cascade; +alter table \`test2_bars\` add constraint \`test2_bars_test2_id_foreign\` foreign key (\`test2_id\`) references \`test2\` (\`id\`) on update cascade on delete cascade; +alter table \`test2_bars\` add constraint \`test2_bars_foo_bar2_id_foreign\` foreign key (\`foo_bar2_id\`) references \`foo_bar2\` (\`id\`) on update cascade on delete cascade; + alter table \`book2_tags\` add constraint \`book2_tags_book2_uuid_pk_foreign\` foreign key (\`book2_uuid_pk\`) references \`book2\` (\`uuid_pk\`) on update cascade on delete cascade; alter table \`book2_tags\` add constraint \`book2_tags_book_tag2_id_foreign\` foreign key (\`book_tag2_id\`) references \`book_tag2\` (\`id\`) on update cascade on delete cascade; @@ -171,6 +179,7 @@ drop table if exists \`author2_following\`; drop table if exists \`author_to_friend\`; drop table if exists \`book_to_tag_unordered\`; drop table if exists \`book2_tags\`; +drop table if exists \`test2_bars\`; drop table if exists \`publisher2_tests\`; drop table if exists \`configuration2\`; drop table if exists \`test2\`; @@ -203,6 +212,7 @@ drop table if exists \`author2_following\`; drop table if exists \`author_to_friend\`; drop table if exists \`book_to_tag_unordered\`; drop table if exists \`book2_tags\`; +drop table if exists \`test2_bars\`; drop table if exists \`publisher2_tests\`; drop table if exists \`configuration2\`; drop table if exists \`test2\`; @@ -292,6 +302,11 @@ create table \`publisher2_tests\` (\`id\` int unsigned not null auto_increment p alter table \`publisher2_tests\` add index \`publisher2_tests_publisher2_id_index\`(\`publisher2_id\`); alter table \`publisher2_tests\` add index \`publisher2_tests_test2_id_index\`(\`test2_id\`); +create table \`test2_bars\` (\`test2_id\` int(11) unsigned not null, \`foo_bar2_id\` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB; +alter table \`test2_bars\` add index \`test2_bars_test2_id_index\`(\`test2_id\`); +alter table \`test2_bars\` add index \`test2_bars_foo_bar2_id_index\`(\`foo_bar2_id\`); +alter table \`test2_bars\` add primary key \`test2_bars_pkey\`(\`test2_id\`, \`foo_bar2_id\`); + create table \`book2_tags\` (\`order\` int unsigned not null auto_increment primary key, \`book2_uuid_pk\` varchar(36) not null, \`book_tag2_id\` bigint unsigned not null) default character set utf8mb4 engine = InnoDB; alter table \`book2_tags\` add index \`book2_tags_book2_uuid_pk_index\`(\`book2_uuid_pk\`); alter table \`book2_tags\` add index \`book2_tags_book_tag2_id_index\`(\`book_tag2_id\`); @@ -348,6 +363,9 @@ alter table \`configuration2\` add constraint \`configuration2_test_id_foreign\` alter table \`publisher2_tests\` add constraint \`publisher2_tests_publisher2_id_foreign\` foreign key (\`publisher2_id\`) references \`publisher2\` (\`id\`) on update cascade on delete cascade; alter table \`publisher2_tests\` add constraint \`publisher2_tests_test2_id_foreign\` foreign key (\`test2_id\`) references \`test2\` (\`id\`) on update cascade on delete cascade; +alter table \`test2_bars\` add constraint \`test2_bars_test2_id_foreign\` foreign key (\`test2_id\`) references \`test2\` (\`id\`) on update cascade on delete cascade; +alter table \`test2_bars\` add constraint \`test2_bars_foo_bar2_id_foreign\` foreign key (\`foo_bar2_id\`) references \`foo_bar2\` (\`id\`) on update cascade on delete cascade; + alter table \`book2_tags\` add constraint \`book2_tags_book2_uuid_pk_foreign\` foreign key (\`book2_uuid_pk\`) references \`book2\` (\`uuid_pk\`) on update cascade on delete cascade; alter table \`book2_tags\` add constraint \`book2_tags_book_tag2_id_foreign\` foreign key (\`book_tag2_id\`) references \`book_tag2\` (\`id\`) on update cascade on delete cascade; @@ -440,6 +458,9 @@ alter table \\"configuration2\\" add constraint \\"configuration2_pkey\\" primar create table \\"publisher2_tests\\" (\\"id\\" serial primary key, \\"publisher2_id\\" int4 not null, \\"test2_id\\" int4 not null); +create table \\"test2_bars\\" (\\"test2_id\\" int4 not null, \\"foo_bar2_id\\" int4 not null); +alter table \\"test2_bars\\" add constraint \\"test2_bars_pkey\\" primary key (\\"test2_id\\", \\"foo_bar2_id\\"); + create table \\"book2_tags\\" (\\"order\\" serial primary key, \\"book2_uuid_pk\\" varchar(36) not null, \\"book_tag2_id\\" bigint not null); create table \\"book_to_tag_unordered\\" (\\"book2_uuid_pk\\" varchar(36) not null, \\"book_tag2_id\\" bigint not null); @@ -472,6 +493,9 @@ alter table \\"configuration2\\" add constraint \\"configuration2_test_id_foreig alter table \\"publisher2_tests\\" add constraint \\"publisher2_tests_publisher2_id_foreign\\" foreign key (\\"publisher2_id\\") references \\"publisher2\\" (\\"id\\") on update cascade on delete cascade; alter table \\"publisher2_tests\\" add constraint \\"publisher2_tests_test2_id_foreign\\" foreign key (\\"test2_id\\") references \\"test2\\" (\\"id\\") on update cascade on delete cascade; +alter table \\"test2_bars\\" add constraint \\"test2_bars_test2_id_foreign\\" foreign key (\\"test2_id\\") references \\"test2\\" (\\"id\\") on update cascade on delete cascade; +alter table \\"test2_bars\\" add constraint \\"test2_bars_foo_bar2_id_foreign\\" foreign key (\\"foo_bar2_id\\") references \\"foo_bar2\\" (\\"id\\") on update cascade on delete cascade; + alter table \\"book2_tags\\" add constraint \\"book2_tags_book2_uuid_pk_foreign\\" foreign key (\\"book2_uuid_pk\\") references \\"book2\\" (\\"uuid_pk\\") on update cascade on delete cascade; alter table \\"book2_tags\\" add constraint \\"book2_tags_book_tag2_id_foreign\\" foreign key (\\"book_tag2_id\\") references \\"book_tag2\\" (\\"id\\") on update cascade on delete cascade; @@ -500,6 +524,7 @@ drop table if exists \\"author2_following\\" cascade; drop table if exists \\"author_to_friend\\" cascade; drop table if exists \\"book_to_tag_unordered\\" cascade; drop table if exists \\"book2_tags\\" cascade; +drop table if exists \\"test2_bars\\" cascade; drop table if exists \\"publisher2_tests\\" cascade; drop table if exists \\"configuration2\\" cascade; drop table if exists \\"test2\\" cascade; @@ -525,6 +550,7 @@ drop table if exists \\"author2_following\\" cascade; drop table if exists \\"author_to_friend\\" cascade; drop table if exists \\"book_to_tag_unordered\\" cascade; drop table if exists \\"book2_tags\\" cascade; +drop table if exists \\"test2_bars\\" cascade; drop table if exists \\"publisher2_tests\\" cascade; drop table if exists \\"configuration2\\" cascade; drop table if exists \\"test2\\" cascade; @@ -578,6 +604,9 @@ alter table \\"configuration2\\" add constraint \\"configuration2_pkey\\" primar create table \\"publisher2_tests\\" (\\"id\\" serial primary key, \\"publisher2_id\\" int4 not null, \\"test2_id\\" int4 not null); +create table \\"test2_bars\\" (\\"test2_id\\" int4 not null, \\"foo_bar2_id\\" int4 not null); +alter table \\"test2_bars\\" add constraint \\"test2_bars_pkey\\" primary key (\\"test2_id\\", \\"foo_bar2_id\\"); + create table \\"book2_tags\\" (\\"order\\" serial primary key, \\"book2_uuid_pk\\" varchar(36) not null, \\"book_tag2_id\\" bigint not null); create table \\"book_to_tag_unordered\\" (\\"book2_uuid_pk\\" varchar(36) not null, \\"book_tag2_id\\" bigint not null); @@ -610,6 +639,9 @@ alter table \\"configuration2\\" add constraint \\"configuration2_test_id_foreig alter table \\"publisher2_tests\\" add constraint \\"publisher2_tests_publisher2_id_foreign\\" foreign key (\\"publisher2_id\\") references \\"publisher2\\" (\\"id\\") on update cascade on delete cascade; alter table \\"publisher2_tests\\" add constraint \\"publisher2_tests_test2_id_foreign\\" foreign key (\\"test2_id\\") references \\"test2\\" (\\"id\\") on update cascade on delete cascade; +alter table \\"test2_bars\\" add constraint \\"test2_bars_test2_id_foreign\\" foreign key (\\"test2_id\\") references \\"test2\\" (\\"id\\") on update cascade on delete cascade; +alter table \\"test2_bars\\" add constraint \\"test2_bars_foo_bar2_id_foreign\\" foreign key (\\"foo_bar2_id\\") references \\"foo_bar2\\" (\\"id\\") on update cascade on delete cascade; + alter table \\"book2_tags\\" add constraint \\"book2_tags_book2_uuid_pk_foreign\\" foreign key (\\"book2_uuid_pk\\") references \\"book2\\" (\\"uuid_pk\\") on update cascade on delete cascade; alter table \\"book2_tags\\" add constraint \\"book2_tags_book_tag2_id_foreign\\" foreign key (\\"book_tag2_id\\") references \\"book_tag2\\" (\\"id\\") on update cascade on delete cascade; @@ -999,6 +1031,11 @@ create table \`publisher2_tests\` (\`id\` int unsigned not null auto_increment p alter table \`publisher2_tests\` add index \`publisher2_tests_publisher2_id_index\`(\`publisher2_id\`); alter table \`publisher2_tests\` add index \`publisher2_tests_test2_id_index\`(\`test2_id\`); +create table \`test2_bars\` (\`test2_id\` int(11) unsigned not null, \`foo_bar2_id\` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB; +alter table \`test2_bars\` add index \`test2_bars_test2_id_index\`(\`test2_id\`); +alter table \`test2_bars\` add index \`test2_bars_foo_bar2_id_index\`(\`foo_bar2_id\`); +alter table \`test2_bars\` add primary key \`test2_bars_pkey\`(\`test2_id\`, \`foo_bar2_id\`); + create table \`book2_tags\` (\`order\` int unsigned not null auto_increment primary key, \`book2_uuid_pk\` varchar(36) not null, \`book_tag2_id\` bigint unsigned not null) default character set utf8mb4 engine = InnoDB; alter table \`book2_tags\` add index \`book2_tags_book2_uuid_pk_index\`(\`book2_uuid_pk\`); alter table \`book2_tags\` add index \`book2_tags_book_tag2_id_index\`(\`book_tag2_id\`); @@ -1055,6 +1092,9 @@ alter table \`configuration2\` add constraint \`configuration2_test_id_foreign\` alter table \`publisher2_tests\` add constraint \`publisher2_tests_publisher2_id_foreign\` foreign key (\`publisher2_id\`) references \`publisher2\` (\`id\`) on update cascade on delete cascade; alter table \`publisher2_tests\` add constraint \`publisher2_tests_test2_id_foreign\` foreign key (\`test2_id\`) references \`test2\` (\`id\`) on update cascade on delete cascade; +alter table \`test2_bars\` add constraint \`test2_bars_test2_id_foreign\` foreign key (\`test2_id\`) references \`test2\` (\`id\`) on update cascade on delete cascade; +alter table \`test2_bars\` add constraint \`test2_bars_foo_bar2_id_foreign\` foreign key (\`foo_bar2_id\`) references \`foo_bar2\` (\`id\`) on update cascade on delete cascade; + alter table \`book2_tags\` add constraint \`book2_tags_book2_uuid_pk_foreign\` foreign key (\`book2_uuid_pk\`) references \`book2\` (\`uuid_pk\`) on update cascade on delete cascade; alter table \`book2_tags\` add constraint \`book2_tags_book_tag2_id_foreign\` foreign key (\`book_tag2_id\`) references \`book_tag2\` (\`id\`) on update cascade on delete cascade; @@ -1131,6 +1171,9 @@ alter table \\"configuration2\\" add constraint \\"configuration2_pkey\\" primar create table \\"publisher2_tests\\" (\\"id\\" serial primary key, \\"publisher2_id\\" int4 not null, \\"test2_id\\" int4 not null); +create table \\"test2_bars\\" (\\"test2_id\\" int4 not null, \\"foo_bar2_id\\" int4 not null); +alter table \\"test2_bars\\" add constraint \\"test2_bars_pkey\\" primary key (\\"test2_id\\", \\"foo_bar2_id\\"); + create table \\"book2_tags\\" (\\"order\\" serial primary key, \\"book2_uuid_pk\\" varchar(36) not null, \\"book_tag2_id\\" bigint not null); create table \\"book_to_tag_unordered\\" (\\"book2_uuid_pk\\" varchar(36) not null, \\"book_tag2_id\\" bigint not null); @@ -1163,6 +1206,9 @@ alter table \\"configuration2\\" add constraint \\"configuration2_test_id_foreig alter table \\"publisher2_tests\\" add constraint \\"publisher2_tests_publisher2_id_foreign\\" foreign key (\\"publisher2_id\\") references \\"publisher2\\" (\\"id\\") on update cascade on delete cascade; alter table \\"publisher2_tests\\" add constraint \\"publisher2_tests_test2_id_foreign\\" foreign key (\\"test2_id\\") references \\"test2\\" (\\"id\\") on update cascade on delete cascade; +alter table \\"test2_bars\\" add constraint \\"test2_bars_test2_id_foreign\\" foreign key (\\"test2_id\\") references \\"test2\\" (\\"id\\") on update cascade on delete cascade; +alter table \\"test2_bars\\" add constraint \\"test2_bars_foo_bar2_id_foreign\\" foreign key (\\"foo_bar2_id\\") references \\"foo_bar2\\" (\\"id\\") on update cascade on delete cascade; + alter table \\"book2_tags\\" add constraint \\"book2_tags_book2_uuid_pk_foreign\\" foreign key (\\"book2_uuid_pk\\") references \\"book2\\" (\\"uuid_pk\\") on update cascade on delete cascade; alter table \\"book2_tags\\" add constraint \\"book2_tags_book_tag2_id_foreign\\" foreign key (\\"book_tag2_id\\") references \\"book_tag2\\" (\\"id\\") on update cascade on delete cascade; diff --git a/tests/entities-sql/FooBar2.ts b/tests/entities-sql/FooBar2.ts index d492ee27f03e..8f33d738ac7d 100644 --- a/tests/entities-sql/FooBar2.ts +++ b/tests/entities-sql/FooBar2.ts @@ -1,6 +1,7 @@ -import { ArrayType, BlobType, Entity, Formula, JsonType, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'; +import { ManyToMany, Collection, Entity, Formula, JsonType, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'; import { BaseEntity22 } from './BaseEntity22'; import { FooBaz2 } from './FooBaz2'; +import { Test2 } from './Test2'; @Entity() export class FooBar2 extends BaseEntity22 { @@ -32,6 +33,9 @@ export class FooBar2 extends BaseEntity22 { @Formula(`(select 123)`) random?: number; + @ManyToMany(() => Test2, t => t.bars) + tests = new Collection(this); + static create(name: string) { const bar = new FooBar2(); bar.name = name; diff --git a/tests/entities-sql/Test2.ts b/tests/entities-sql/Test2.ts index b0164719cfd7..bfde357b0b9c 100644 --- a/tests/entities-sql/Test2.ts +++ b/tests/entities-sql/Test2.ts @@ -1,6 +1,7 @@ -import { Collection, Entity, OneToMany, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'; +import { Collection, Entity, ManyToMany, OneToMany, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'; import { Book2 } from './Book2'; import { Configuration2 } from './Configuration2'; +import { FooBar2 } from './FooBar2'; @Entity() export class Test2 { @@ -20,6 +21,9 @@ export class Test2 { @Property({ version: true }) version!: number; + @ManyToMany(() => FooBar2) + bars = new Collection(this); + constructor(props: Partial = {}) { this.id = props.id!; this.name = props.name!; diff --git a/tests/issues/GH369.test.ts b/tests/issues/GH369.test.ts index 717da7620a5f..3f28bb68a5b1 100644 --- a/tests/issues/GH369.test.ts +++ b/tests/issues/GH369.test.ts @@ -34,10 +34,9 @@ describe('GH issue 369', () => { beforeAll(async () => { orm = await MikroORM.init({ entities: [A, B], - dbName: __dirname + '/../../temp/mikro_orm_test_gh369.db', + dbName: ':memory:', type: 'sqlite', }); - await new SchemaGenerator(orm.em).dropSchema(); await new SchemaGenerator(orm.em).createSchema(); }); diff --git a/tests/issues/GH467.test.ts b/tests/issues/GH467.test.ts index 54f5febcbc28..8219cf778a47 100644 --- a/tests/issues/GH467.test.ts +++ b/tests/issues/GH467.test.ts @@ -30,10 +30,9 @@ describe('GH issue 467', () => { beforeAll(async () => { orm = await MikroORM.init({ entities: [A, B], - dbName: __dirname + '/../../temp/mikro_orm_test_gh467.db', + dbName: ':memory:', type: 'sqlite', }); - await orm.getSchemaGenerator().dropSchema(); await orm.getSchemaGenerator().createSchema(); }); diff --git a/tests/mysql-schema.sql b/tests/mysql-schema.sql index 27f6ae5a3824..59c4e1bfceb7 100644 --- a/tests/mysql-schema.sql +++ b/tests/mysql-schema.sql @@ -7,6 +7,7 @@ drop table if exists `author_to_friend`; drop table if exists `book_to_tag_unordered`; drop table if exists `book2_tags`; drop table if exists `publisher2_tests`; +drop table if exists `test2_bars`; drop table if exists `configuration2`; drop table if exists `test2`; drop table if exists `book2`; @@ -115,6 +116,11 @@ create table `publisher2_tests` (`id` int unsigned not null auto_increment prima alter table `publisher2_tests` add index `publisher2_tests_publisher2_id_index`(`publisher2_id`); alter table `publisher2_tests` add index `publisher2_tests_test2_id_index`(`test2_id`); +create table `test2_bars` (`test2_id` int(11) unsigned not null, `foo_bar2_id` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB; +alter table `test2_bars` add index `test2_bars_test2_id_index`(`test2_id`); +alter table `test2_bars` add index `test2_bars_foo_bar2_id_index`(`foo_bar2_id`); +alter table `test2_bars` add primary key `test2_bars_pkey`(`test2_id`, `foo_bar2_id`); + create table `book2_tags` (`order` int unsigned not null auto_increment primary key, `book2_uuid_pk` varchar(36) not null, `book_tag2_id` bigint unsigned not null) default character set utf8mb4 engine = InnoDB; alter table `book2_tags` add index `book2_tags_book2_uuid_pk_index`(`book2_uuid_pk`); alter table `book2_tags` add index `book2_tags_book_tag2_id_index`(`book_tag2_id`); @@ -172,6 +178,9 @@ alter table `configuration2` add constraint `configuration2_test_id_foreign` for alter table `publisher2_tests` add constraint `publisher2_tests_publisher2_id_foreign` foreign key (`publisher2_id`) references `publisher2` (`id`) on update cascade on delete cascade; alter table `publisher2_tests` add constraint `publisher2_tests_test2_id_foreign` foreign key (`test2_id`) references `test2` (`id`) on update cascade on delete cascade; +alter table `test2_bars` add constraint `test2_bars_test2_id_foreign` foreign key (`test2_id`) references `test2` (`id`) on update cascade on delete cascade; +alter table `test2_bars` add constraint `test2_bars_foo_bar2_id_foreign` foreign key (`foo_bar2_id`) references `foo_bar2` (`id`) on update cascade on delete cascade; + alter table `book2_tags` add constraint `book2_tags_book2_uuid_pk_foreign` foreign key (`book2_uuid_pk`) references `book2` (`uuid_pk`) on update cascade on delete cascade; alter table `book2_tags` add constraint `book2_tags_book_tag2_id_foreign` foreign key (`book_tag2_id`) references `book_tag2` (`id`) on update cascade on delete cascade; diff --git a/tests/postgre-schema.sql b/tests/postgre-schema.sql index b6edaf1e360d..d5f642a5c17d 100644 --- a/tests/postgre-schema.sql +++ b/tests/postgre-schema.sql @@ -6,6 +6,7 @@ drop table if exists "author_to_friend" cascade; drop table if exists "book_to_tag_unordered" cascade; drop table if exists "book2_tags" cascade; drop table if exists "publisher2_tests" cascade; +drop table if exists "test2_bars" cascade; drop table if exists "configuration2" cascade; drop table if exists "test2" cascade; drop table if exists "book2" cascade; @@ -66,6 +67,9 @@ alter table "configuration2" add constraint "configuration2_pkey" primary key (" create table "publisher2_tests" ("id" serial primary key, "publisher2_id" int4 not null, "test2_id" int4 not null); +create table "test2_bars" ("test2_id" int4 not null, "foo_bar2_id" int4 not null); +alter table "test2_bars" add constraint "test2_bars_pkey" primary key ("test2_id", "foo_bar2_id"); + create table "book2_tags" ("order" serial primary key, "book2_uuid_pk" varchar(36) not null, "book_tag2_id" bigint not null); create table "book_to_tag_unordered" ("book2_uuid_pk" varchar(36) not null, "book_tag2_id" bigint not null); @@ -98,6 +102,9 @@ alter table "configuration2" add constraint "configuration2_test_id_foreign" for alter table "publisher2_tests" add constraint "publisher2_tests_publisher2_id_foreign" foreign key ("publisher2_id") references "publisher2" ("id") on update cascade on delete cascade; alter table "publisher2_tests" add constraint "publisher2_tests_test2_id_foreign" foreign key ("test2_id") references "test2" ("id") on update cascade on delete cascade; +alter table "test2_bars" add constraint "test2_bars_test2_id_foreign" foreign key ("test2_id") references "test2" ("id") on update cascade on delete cascade; +alter table "test2_bars" add constraint "test2_bars_foo_bar2_id_foreign" foreign key ("foo_bar2_id") references "foo_bar2" ("id") on update cascade on delete cascade; + alter table "book2_tags" add constraint "book2_tags_book2_uuid_pk_foreign" foreign key ("book2_uuid_pk") references "book2" ("uuid_pk") on update cascade on delete cascade; alter table "book2_tags" add constraint "book2_tags_book_tag2_id_foreign" foreign key ("book_tag2_id") references "book_tag2" ("id") on update cascade on delete cascade; diff --git a/yarn.lock b/yarn.lock index 899906ef8eb7..933e3303bd47 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3502,10 +3502,10 @@ escape-string-regexp@^2.0.0: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz#a30304e99daa32e23b2fd20f51babd07cffca344" integrity sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w== -escaya@^0.0.47: - version "0.0.47" - resolved "https://registry.yarnpkg.com/escaya/-/escaya-0.0.47.tgz#4316a68fe4f7ee43681a72de17f2d4b2adcfd4ff" - integrity sha512-dVhBDCcUY5Rva78u3SqGxBOihUGsz4JI4l0pta8GiN5tRLMucshTZ6ntq3FPw1LBuRbjcObb45INPwYxiqEvvQ== +escaya@^0.0.49: + version "0.0.49" + resolved "https://registry.yarnpkg.com/escaya/-/escaya-0.0.49.tgz#3295f5c3a1cb2c29cf8cd839fbf4240cc422f278" + integrity sha512-Wo5yFmYe+8+YSDztQzJ4LplPttNmQl4rb3TjyAR6zvZUgWiPKjacXLGvdtqprHCK+Z1mVWcAKACRKlYF9JgqDg== escodegen@^1.14.1: version "1.14.3" @@ -4536,7 +4536,7 @@ iconv-lite@0.4.24, iconv-lite@^0.4.24, iconv-lite@^0.4.4: dependencies: safer-buffer ">= 2.1.2 < 3" -iconv-lite@^0.5.0, iconv-lite@^0.5.1: +iconv-lite@^0.5.1: version "0.5.2" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.5.2.tgz#af6d628dccfb463b7364d97f715e4b74b8c8c2b8" integrity sha512-kERHXvpSaB4aU3eANwidg79K8FlrN77m8G9V+0vOR3HYaRifrlwMEpT7ZBJqLSEIHnEgJTHcWK82wwLwwKwtag== @@ -5907,6 +5907,13 @@ lru-cache@^5.1.1: dependencies: yallist "^3.0.2" +lru-cache@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" + integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA== + dependencies: + yallist "^4.0.0" + macos-release@^2.2.0: version "2.4.1" resolved "https://registry.yarnpkg.com/macos-release/-/macos-release-2.4.1.tgz#64033d0ec6a5e6375155a74b1a1eba8e509820ac" @@ -6346,15 +6353,16 @@ mute-stream@~0.0.4: resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA== -mysql2@sidorares/node-mysql2#master: - version "2.1.0" - resolved "https://codeload.github.com/sidorares/node-mysql2/tar.gz/3133dc12e969c650f2e6a586e17af26f268599f0" +mysql2@^2.2.5: + version "2.2.5" + resolved "https://registry.yarnpkg.com/mysql2/-/mysql2-2.2.5.tgz#72624ffb4816f80f96b9c97fedd8c00935f9f340" + integrity sha512-XRqPNxcZTpmFdXbJqb+/CtYVLCx14x1RTeNMD4954L331APu75IC74GDqnZMEt1kwaXy6TySo55rF2F3YJS78g== dependencies: denque "^1.4.1" generate-function "^2.3.1" - iconv-lite "^0.5.0" + iconv-lite "^0.6.2" long "^4.0.0" - lru-cache "^5.1.1" + lru-cache "^6.0.0" named-placeholders "^1.1.2" seq-queue "^0.0.5" sqlstring "^2.3.2" @@ -9253,6 +9261,11 @@ yallist@^3.0.0, yallist@^3.0.2, yallist@^3.0.3: resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd" integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g== +yallist@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72" + integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A== + yaml@^1.10.0, yaml@^1.7.2: version "1.10.0" resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e"