diff --git a/packages/entity-generator/src/EntityGenerator.ts b/packages/entity-generator/src/EntityGenerator.ts index 97453c4f6f8a..28252140d496 100644 --- a/packages/entity-generator/src/EntityGenerator.ts +++ b/packages/entity-generator/src/EntityGenerator.ts @@ -1,4 +1,3 @@ -import { ensureDir, writeFile } from 'fs-extra'; import { type EntityMetadata, type EntityProperty, @@ -17,8 +16,9 @@ import { type EntityManager, type SchemaHelper, } from '@mikro-orm/knex'; -import { SourceFile } from './SourceFile'; +import { ensureDir, writeFile } from 'fs-extra'; import { EntitySchemaSourceFile } from './EntitySchemaSourceFile'; +import { SourceFile } from './SourceFile'; export class EntityGenerator { @@ -122,39 +122,96 @@ export class EntityGenerator { this.referencedEntities.add(meta); } + + // Entities with non-composite PKs are never pivot tables. Skip. + if (!meta.compositePK) { + continue; + } + + // Entities where there are not exactly 2 PK relations that are both ManyToOne are never pivot tables. Skip. + const pkRelations = meta.relations.filter(rel => rel.primary); if ( - meta.compositePK && // needs to have composite PK - meta.relations.length === 2 && // there are exactly two relation properties - !meta.relations.some(rel => !rel.primary || rel.kind !== ReferenceKind.MANY_TO_ONE) && // all relations are m:1 and PKs - ( - // all properties are relations... - meta.relations.length === meta.props.length - // ... or at least all fields involved are only the fields of the relations - || (new Set(meta.props.flatMap(prop => prop.fieldNames)).size === (new Set(meta.relations.flatMap(rel => rel.fieldNames)).size)) - ) + pkRelations.length !== 2 || + pkRelations.some(rel => rel.kind !== ReferenceKind.MANY_TO_ONE) ) { - meta.pivotTable = true; - const owner = metadata.find(m => m.className === meta.relations[0].type); + continue; + } - if (!owner) { - continue; + const pkRelationFields = new Set(pkRelations.flatMap(rel => rel.fieldNames)); + const nonPkFields = Array.from(new Set(meta.props.flatMap(prop => prop.fieldNames))).filter(fieldName => !pkRelationFields.has(fieldName)); + + let fixedOrderColumn: string | undefined; + + // If there are any fields other than the ones in the two PK relations, table may or may not be a pivot one. + // Check further and skip on disqualification. + if (nonPkFields.length > 0) { + const pkRelationNames = pkRelations.map(rel => rel.name); + let otherProps = meta.props + .filter(prop => !pkRelationNames.includes(prop.name) && + prop.persist !== false && // Skip checking non-persist props + prop.fieldNames.some(fieldName => nonPkFields.includes(fieldName)), + ); + + // Deal with the auto increment column first. That is the column used for fixed ordering, if present. + const autoIncrementProp = otherProps.find(prop => prop.autoincrement && prop.fieldNames.length === 1); + if (autoIncrementProp) { + otherProps = otherProps.filter(prop => prop !== autoIncrementProp); + fixedOrderColumn = autoIncrementProp.fieldNames[0]; } - const name = this.namingStrategy.columnNameToProperty(meta.tableName.replace(new RegExp('^' + owner.tableName + '_'), '')); - const ownerProp = { - name, - kind: ReferenceKind.MANY_TO_MANY, - pivotTable: meta.tableName, - type: meta.relations[1].type, - joinColumns: meta.relations[0].fieldNames, - inverseJoinColumns: meta.relations[1].fieldNames, - } as EntityProperty; + if (otherProps.some(prop => { + // If the prop is non-nullable and unique, it will trivially end up causing issues. + // Disqualify entity as a pivot table. + if (!prop.nullable && prop.unique) { + return true; + } - if (this.referencedEntities.has(meta)) { - ownerProp.pivotEntity = meta.className; + // Scalar props need to also have a default or be generated ones. + if (prop.kind === ReferenceKind.SCALAR) { + return !(typeof prop.defaultRaw !== 'undefined' || prop.generated); + } + + // Non-scalar props need to also be optional. + // Even if they have a default, we've already checked that not explicitly setting the property + // means the default is either NULL, or a non-unique non-null value, making it safe to use in a pivot entity. + return !prop.optional; + })) { + continue; + } + + // If this now proven pivot entity has persistent props other than the fixed order column, + // output it, by considering it as a referenced one. + if (otherProps.length > 0) { + this.referencedEntities.add(meta); } - owner.addProperty(ownerProp); } + + meta.pivotTable = true; + const owner = metadata.find(m => m.className === meta.relations[0].type); + + if (!owner) { + continue; + } + + const name = this.namingStrategy.columnNameToProperty(meta.tableName.replace(new RegExp('^' + owner.tableName + '_'), '')); + const ownerProp = { + name, + kind: ReferenceKind.MANY_TO_MANY, + pivotTable: meta.tableName, + type: meta.relations[1].type, + joinColumns: meta.relations[0].fieldNames, + inverseJoinColumns: meta.relations[1].fieldNames, + } as EntityProperty; + + if (this.referencedEntities.has(meta)) { + ownerProp.pivotEntity = meta.className; + } + if (fixedOrderColumn) { + ownerProp.fixedOrder = true; + ownerProp.fixedOrderColumn = fixedOrderColumn; + } + + owner.addProperty(ownerProp); } } diff --git a/packages/entity-generator/src/SourceFile.ts b/packages/entity-generator/src/SourceFile.ts index 337ae6e17192..065f90207469 100644 --- a/packages/entity-generator/src/SourceFile.ts +++ b/packages/entity-generator/src/SourceFile.ts @@ -365,6 +365,13 @@ export class SourceFile { } else { options.inverseJoinColumns = `[${prop.inverseJoinColumns.map(this.quote).join(', ')}]`; } + + if (prop.fixedOrder) { + options.fixedOrder = true; + if (prop.fixedOrderColumn !== this.namingStrategy.referenceColumnName()) { + options.fixedOrderColumn = prop.fixedOrderColumn; + } + } } protected getOneToManyDecoratorOptions(options: Dictionary, prop: EntityProperty) { diff --git a/tests/features/entity-generator/__snapshots__/EntityGenerator.mysql.test.ts.snap b/tests/features/entity-generator/__snapshots__/EntityGenerator.mysql.test.ts.snap index 8336c2df8597..9cca57fecba8 100644 --- a/tests/features/entity-generator/__snapshots__/EntityGenerator.mysql.test.ts.snap +++ b/tests/features/entity-generator/__snapshots__/EntityGenerator.mysql.test.ts.snap @@ -425,6 +425,7 @@ export class FooBar2 { blob2?: Buffer; array?: string; objectProperty?: any; + fooParam2 = new Collection(this); fooBarInverse?: Ref; barInverse = new Collection(this); barsInverse = new Collection(this); @@ -457,6 +458,14 @@ export const FooBar2Schema = new EntitySchema({ blob2: { type: 'Buffer', length: 65535, nullable: true }, array: { type: 'string', columnType: 'text', nullable: true }, objectProperty: { type: 'any', columnType: 'json', nullable: true }, + fooParam2: { + kind: 'm:n', + entity: () => FooBaz2, + pivotTable: 'foo_param2', + pivotEntity: () => FooParam2, + joinColumn: 'bar_id', + inverseJoinColumn: 'baz_id', + }, fooBarInverse: { kind: '1:1', entity: () => Test2, ref: true, mappedBy: 'fooBar' }, barInverse: { kind: '1:m', entity: () => FooParam2, mappedBy: 'bar' }, barsInverse: { kind: 'm:n', entity: () => Test2, mappedBy: 'bars' }, @@ -464,6 +473,7 @@ export const FooBar2Schema = new EntitySchema({ }); ", "import { Collection, EntitySchema, OptionalProps } from '@mikro-orm/core'; +import { FooBar2 } from './FooBar2'; import { FooParam2 } from './FooParam2'; export class FooBaz2 { @@ -472,6 +482,7 @@ export class FooBaz2 { name!: string; version!: Date; bazInverse = new Collection(this); + fooParam2Inverse = new Collection(this); } export const FooBaz2Schema = new EntitySchema({ @@ -481,6 +492,7 @@ export const FooBaz2Schema = new EntitySchema({ name: { type: 'string', length: 255 }, version: { type: 'Date', length: 3, defaultRaw: \`current_timestamp(3)\` }, bazInverse: { kind: '1:m', entity: () => FooParam2, mappedBy: 'baz' }, + fooParam2Inverse: { kind: 'm:n', entity: () => FooBar2, mappedBy: 'fooParam2' }, }, }); ", @@ -1032,8 +1044,9 @@ export class Dummy2 { } ", - "import { Entity, OneToOne, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToOne, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; import { FooBaz2 } from './FooBaz2'; +import { FooParam2 } from './FooParam2'; @Entity() export class FooBar2 { @@ -1070,6 +1083,9 @@ export class FooBar2 { @Property({ columnType: 'json', nullable: true }) objectProperty?: any; + @ManyToMany({ entity: () => FooBaz2, pivotTable: 'foo_param2', pivotEntity: () => FooParam2, joinColumn: 'bar_id', inverseJoinColumn: 'baz_id' }) + fooParam2 = new Collection(this); + } ", "import { Entity, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; @@ -1632,6 +1648,9 @@ export class FooBar2 { @Property({ columnType: 'json', nullable: true }) objectProperty?: any; + @ManyToMany({ entity: () => FooBaz2, pivotTable: 'foo_param2', pivotEntity: () => FooParam2, joinColumn: 'bar_id', inverseJoinColumn: 'baz_id' }) + fooParam2 = new Collection(this); + @OneToOne({ entity: () => Test2, mappedBy: 'fooBar' }) fooBarInverse?: Test2; @@ -1643,7 +1662,8 @@ export class FooBar2 { } ", - "import { Collection, Entity, OneToMany, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; +import { FooBar2 } from './FooBar2'; import { FooParam2 } from './FooParam2'; @Entity() @@ -1663,6 +1683,9 @@ export class FooBaz2 { @OneToMany({ entity: () => FooParam2, mappedBy: 'baz' }) bazInverse = new Collection(this); + @ManyToMany({ entity: () => FooBar2, mappedBy: 'fooParam2' }) + fooParam2Inverse = new Collection(this); + } ", "import { Entity, ManyToOne, OptionalProps, PrimaryKeyProp, Property } from '@mikro-orm/core'; @@ -2230,6 +2253,9 @@ export class FooBar2 { @Property({ columnType: 'json', nullable: true }) objectProperty?: any; + @ManyToMany({ entity: () => FooBaz2, pivotTable: 'foo_param2', pivotEntity: () => FooParam2, joinColumn: 'bar_id', inverseJoinColumn: 'baz_id' }) + fooParam2 = new Collection(this); + @OneToOne({ entity: () => Test2, ref: true, mappedBy: 'fooBar' }) fooBarInverse?: Ref; @@ -2241,7 +2267,8 @@ export class FooBar2 { } ", - "import { Collection, Entity, OneToMany, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; +import { FooBar2 } from './FooBar2'; import { FooParam2 } from './FooParam2'; @Entity() @@ -2261,6 +2288,9 @@ export class FooBaz2 { @OneToMany({ entity: () => FooParam2, mappedBy: 'baz' }) bazInverse = new Collection(this); + @ManyToMany({ entity: () => FooBar2, mappedBy: 'fooParam2' }) + fooParam2Inverse = new Collection(this); + } ", "import { Entity, ManyToOne, OptionalProps, PrimaryKeyProp, Property, Ref } from '@mikro-orm/core'; @@ -2740,8 +2770,9 @@ export class Dummy2 { } ", - "import { Entity, OneToOne, OptionalProps, PrimaryKey, Property, Ref } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToOne, OptionalProps, PrimaryKey, Property, Ref } from '@mikro-orm/core'; import { FooBaz2 } from './FooBaz2.js'; +import { FooParam2 } from './FooParam2.js'; @Entity() export class FooBar2 { @@ -2778,6 +2809,9 @@ export class FooBar2 { @Property({ columnType: 'json', nullable: true }) objectProperty?: any; + @ManyToMany({ entity: () => FooBaz2, pivotTable: 'foo_param2', pivotEntity: () => FooParam2, joinColumn: 'bar_id', inverseJoinColumn: 'baz_id' }) + fooParam2 = new Collection(this); + } ", "import { Entity, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; @@ -3303,8 +3337,9 @@ export class Dummy2 { } ", - "import { Entity, OneToOne, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToOne, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; import { FooBaz2 } from './FooBaz2'; +import { FooParam2 } from './FooParam2'; @Entity() export class FooBar2 { @@ -3341,6 +3376,9 @@ export class FooBar2 { @Property({ columnType: 'json', nullable: true }) objectProperty?: any; + @ManyToMany({ entity: () => FooBaz2, pivotTable: 'foo_param2', pivotEntity: () => FooParam2, joinColumn: 'bar_id', inverseJoinColumn: 'baz_id' }) + fooParam2 = new Collection(this); + } ", "import { Entity, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; diff --git a/tests/features/entity-generator/__snapshots__/EntityGenerator.postgres.test.ts.snap b/tests/features/entity-generator/__snapshots__/EntityGenerator.postgres.test.ts.snap index cfd9f120c91f..4b8222b2f606 100644 --- a/tests/features/entity-generator/__snapshots__/EntityGenerator.postgres.test.ts.snap +++ b/tests/features/entity-generator/__snapshots__/EntityGenerator.postgres.test.ts.snap @@ -219,8 +219,9 @@ export class Configuration2 { } ", - "import { Entity, OneToOne, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToOne, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; import { FooBaz2 } from './FooBaz2'; +import { FooParam2 } from './FooParam2'; @Entity() export class FooBar2 { @@ -257,6 +258,9 @@ export class FooBar2 { @Property({ columnType: 'jsonb', nullable: true }) objectProperty?: any; + @ManyToMany({ entity: () => FooBaz2, pivotTable: 'foo_param2', pivotEntity: () => FooParam2, joinColumn: 'bar_id', inverseJoinColumn: 'baz_id' }) + fooParam2 = new Collection(this); + } ", "import { Entity, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; @@ -620,8 +624,9 @@ export class Configuration2 { } ", - "import { Entity, OneToOne, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToOne, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; import { FooBaz2 } from './FooBaz2'; +import { FooParam2 } from './FooParam2'; @Entity() export class FooBar2 { @@ -658,6 +663,9 @@ export class FooBar2 { @Property({ columnType: 'jsonb', nullable: true }) objectProperty?: any; + @ManyToMany({ entity: () => FooBaz2, pivotTable: 'foo_param2', pivotEntity: () => FooParam2, joinColumn: 'bar_id', inverseJoinColumn: 'baz_id' }) + fooParam2 = new Collection(this); + } ", "import { Entity, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; diff --git a/tests/features/entity-generator/__snapshots__/OverlapFks.mysql.test.ts.snap b/tests/features/entity-generator/__snapshots__/OverlapFks.mysql.test.ts.snap index 6089b4743913..cc4d64a2f2a3 100644 --- a/tests/features/entity-generator/__snapshots__/OverlapFks.mysql.test.ts.snap +++ b/tests/features/entity-generator/__snapshots__/OverlapFks.mysql.test.ts.snap @@ -72,7 +72,9 @@ export class ProductSellers { } ", - "import { Entity, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; +import { Countries } from './Countries'; +import { ProductCountryMap } from './ProductCountryMap'; @Entity() export class Products { @@ -94,6 +96,9 @@ export class Products { @Property({ default: 0 }) currentQuantity: number = 0; + @ManyToMany({ entity: () => Countries, pivotTable: 'product_country_map', pivotEntity: () => ProductCountryMap, joinColumn: 'product_id', inverseJoinColumn: 'country' }) + productCountryMap = new Collection(this); + } ", "import { Entity, Index, ManyToOne, OptionalProps, PrimaryKey, PrimaryKeyProp, Property } from '@mikro-orm/core'; @@ -134,7 +139,9 @@ export class Sales { } ", - "import { Entity, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; +import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; @Entity() export class Sellers { @@ -148,6 +155,9 @@ export class Sellers { @Property({ length: 255 }) name!: string; + @ManyToMany({ entity: () => Products, pivotTable: 'product_sellers', pivotEntity: () => ProductSellers, joinColumn: 'seller_id', inverseJoinColumn: 'product_id' }) + productSellers = new Collection(this); + } ", ] @@ -236,7 +246,8 @@ export const ProductSellersSchema = new EntitySchema({ }, }); ", - "import { EntitySchema, OptionalProps, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, EntitySchema, OptionalProps, PrimaryKeyProp } from '@mikro-orm/core'; +import { Countries } from './Countries'; export class Products { [PrimaryKeyProp]?: 'productId'; @@ -245,6 +256,7 @@ export class Products { name!: string; currentPrice!: string; currentQuantity: number = 0; + productCountryMap = new Collection(this); } export const ProductsSchema = new EntitySchema({ @@ -254,6 +266,14 @@ export const ProductsSchema = new EntitySchema({ name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, currentPrice: { type: 'string', columnType: 'numeric(10,2)' }, currentQuantity: { type: 'number', default: 0 }, + productCountryMap: { + kind: 'm:n', + entity: () => Countries, + pivotTable: 'product_country_map', + pivotEntity: () => ProductCountryMap, + joinColumn: 'product_id', + inverseJoinColumn: 'country', + }, }, }); ", @@ -304,12 +324,14 @@ export const SalesSchema = new EntitySchema({ }, }); ", - "import { EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; +import { Products } from './Products'; export class Sellers { [PrimaryKeyProp]?: 'sellerId'; sellerId!: number; name!: string; + productSellers = new Collection(this); } export const SellersSchema = new EntitySchema({ @@ -317,6 +339,14 @@ export const SellersSchema = new EntitySchema({ properties: { sellerId: { primary: true, type: 'number' }, name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, + productSellers: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_sellers', + pivotEntity: () => ProductSellers, + joinColumn: 'seller_id', + inverseJoinColumn: 'product_id', + }, }, }); ", @@ -395,7 +425,9 @@ export class ProductSellers { } ", - "import { Entity, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; +import { Countries } from './Countries'; +import { ProductCountryMap } from './ProductCountryMap'; @Entity() export class Products { @@ -417,6 +449,9 @@ export class Products { @Property({ default: 0 }) currentQuantity: number = 0; + @ManyToMany({ entity: () => Countries, pivotTable: 'product_country_map', pivotEntity: () => ProductCountryMap, joinColumn: 'product_id', inverseJoinColumn: 'country' }) + productCountryMap = new Collection(this); + } ", "import { Entity, Index, ManyToOne, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Ref } from '@mikro-orm/core'; @@ -457,7 +492,9 @@ export class Sales { } ", - "import { Entity, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; +import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; @Entity() export class Sellers { @@ -471,6 +508,9 @@ export class Sellers { @Property({ length: 255 }) name!: string; + @ManyToMany({ entity: () => Products, pivotTable: 'product_sellers', pivotEntity: () => ProductSellers, joinColumn: 'seller_id', inverseJoinColumn: 'product_id' }) + productSellers = new Collection(this); + } ", ] @@ -572,7 +612,8 @@ export const ProductSellersSchema = new EntitySchema({ }, }); ", - "import { EntitySchema, OptionalProps, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, EntitySchema, OptionalProps, PrimaryKeyProp } from '@mikro-orm/core'; +import { Countries } from './Countries'; export class Products { [PrimaryKeyProp]?: 'productId'; @@ -581,6 +622,7 @@ export class Products { name!: string; currentPrice!: string; currentQuantity: number = 0; + productCountryMap = new Collection(this); } export const ProductsSchema = new EntitySchema({ @@ -590,6 +632,14 @@ export const ProductsSchema = new EntitySchema({ name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, currentPrice: { type: 'string', columnType: 'numeric(10,2)' }, currentQuantity: { type: 'number', default: 0 }, + productCountryMap: { + kind: 'm:n', + entity: () => Countries, + pivotTable: 'product_country_map', + pivotEntity: () => ProductCountryMap, + joinColumn: 'product_id', + inverseJoinColumn: 'country', + }, }, }); ", @@ -644,12 +694,14 @@ export const SalesSchema = new EntitySchema({ }, }); ", - "import { EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; +import { Products } from './Products'; export class Sellers { [PrimaryKeyProp]?: 'sellerId'; sellerId!: number; name!: string; + productSellers = new Collection(this); } export const SellersSchema = new EntitySchema({ @@ -657,6 +709,14 @@ export const SellersSchema = new EntitySchema({ properties: { sellerId: { primary: true, type: 'number' }, name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, + productSellers: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_sellers', + pivotEntity: () => ProductSellers, + joinColumn: 'seller_id', + inverseJoinColumn: 'product_id', + }, }, }); ", @@ -665,8 +725,9 @@ export const SellersSchema = new EntitySchema({ exports[`overlap_fk_example scalarPropertiesForRelations=always bidirectionalRelations=true identifiedReferences=false entitySchema=false: dump 1`] = ` [ - "import { Collection, Entity, OneToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; @Entity() export class Countries { @@ -679,6 +740,9 @@ export class Countries { @OneToMany({ entity: () => ProductCountryMap, mappedBy: 'countries' }) countriesInverse = new Collection(this); + @ManyToMany({ entity: () => Products, mappedBy: 'productCountryMap' }) + productCountryMapInverse = new Collection(this); + } ", "import { Collection, Entity, Index, ManyToOne, OneToMany, OptionalProps, PrimaryKeyProp, Property } from '@mikro-orm/core'; @@ -747,8 +811,11 @@ export class ProductSellers { } ", - "import { Collection, Entity, OneToMany, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; +import { Countries } from './Countries'; +import { ProductCountryMap } from './ProductCountryMap'; import { ProductSellers } from './ProductSellers'; +import { Sellers } from './Sellers'; @Entity() export class Products { @@ -770,9 +837,15 @@ export class Products { @Property({ default: 0 }) currentQuantity: number = 0; + @ManyToMany({ entity: () => Countries, pivotTable: 'product_country_map', pivotEntity: () => ProductCountryMap, joinColumn: 'product_id', inverseJoinColumn: 'country' }) + productCountryMap = new Collection(this); + @OneToMany({ entity: () => ProductSellers, mappedBy: 'product' }) productInverse = new Collection(this); + @ManyToMany({ entity: () => Sellers, mappedBy: 'productSellers' }) + productSellersInverse = new Collection(this); + } ", "import { Entity, Index, ManyToOne, OptionalProps, PrimaryKey, PrimaryKeyProp, Property } from '@mikro-orm/core'; @@ -813,8 +886,9 @@ export class Sales { } ", - "import { Collection, Entity, OneToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; @Entity() export class Sellers { @@ -828,6 +902,9 @@ export class Sellers { @Property({ length: 255 }) name!: string; + @ManyToMany({ entity: () => Products, pivotTable: 'product_sellers', pivotEntity: () => ProductSellers, joinColumn: 'seller_id', inverseJoinColumn: 'product_id' }) + productSellers = new Collection(this); + @OneToMany({ entity: () => ProductSellers, mappedBy: 'seller' }) sellerInverse = new Collection(this); @@ -840,11 +917,13 @@ exports[`overlap_fk_example scalarPropertiesForRelations=always bidirectionalRel [ "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; export class Countries { [PrimaryKeyProp]?: 'code'; code!: unknown; countriesInverse = new Collection(this); + productCountryMapInverse = new Collection(this); } export const CountriesSchema = new EntitySchema({ @@ -852,6 +931,7 @@ export const CountriesSchema = new EntitySchema({ properties: { code: { primary: true, type: 'unknown', columnType: 'char(2)' }, countriesInverse: { kind: '1:m', entity: () => ProductCountryMap, mappedBy: 'countries' }, + productCountryMapInverse: { kind: 'm:n', entity: () => Products, mappedBy: 'productCountryMap' }, }, }); ", @@ -929,7 +1009,9 @@ export const ProductSellersSchema = new EntitySchema({ }); ", "import { Collection, EntitySchema, OptionalProps, PrimaryKeyProp } from '@mikro-orm/core'; +import { Countries } from './Countries'; import { ProductSellers } from './ProductSellers'; +import { Sellers } from './Sellers'; export class Products { [PrimaryKeyProp]?: 'productId'; @@ -938,7 +1020,9 @@ export class Products { name!: string; currentPrice!: string; currentQuantity: number = 0; + productCountryMap = new Collection(this); productInverse = new Collection(this); + productSellersInverse = new Collection(this); } export const ProductsSchema = new EntitySchema({ @@ -948,7 +1032,16 @@ export const ProductsSchema = new EntitySchema({ name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, currentPrice: { type: 'string', columnType: 'numeric(10,2)' }, currentQuantity: { type: 'number', default: 0 }, + productCountryMap: { + kind: 'm:n', + entity: () => Countries, + pivotTable: 'product_country_map', + pivotEntity: () => ProductCountryMap, + joinColumn: 'product_id', + inverseJoinColumn: 'country', + }, productInverse: { kind: '1:m', entity: () => ProductSellers, mappedBy: 'product' }, + productSellersInverse: { kind: 'm:n', entity: () => Sellers, mappedBy: 'productSellers' }, }, }); ", @@ -1001,11 +1094,13 @@ export const SalesSchema = new EntitySchema({ ", "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; export class Sellers { [PrimaryKeyProp]?: 'sellerId'; sellerId!: number; name!: string; + productSellers = new Collection(this); sellerInverse = new Collection(this); } @@ -1014,6 +1109,14 @@ export const SellersSchema = new EntitySchema({ properties: { sellerId: { primary: true, type: 'number' }, name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, + productSellers: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_sellers', + pivotEntity: () => ProductSellers, + joinColumn: 'seller_id', + inverseJoinColumn: 'product_id', + }, sellerInverse: { kind: '1:m', entity: () => ProductSellers, mappedBy: 'seller' }, }, }); @@ -1023,8 +1126,9 @@ export const SellersSchema = new EntitySchema({ exports[`overlap_fk_example scalarPropertiesForRelations=always bidirectionalRelations=true identifiedReferences=true entitySchema=false: dump 1`] = ` [ - "import { Collection, Entity, OneToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; @Entity() export class Countries { @@ -1037,6 +1141,9 @@ export class Countries { @OneToMany({ entity: () => ProductCountryMap, mappedBy: 'countries' }) countriesInverse = new Collection(this); + @ManyToMany({ entity: () => Products, mappedBy: 'productCountryMap' }) + productCountryMapInverse = new Collection(this); + } ", "import { Collection, Entity, Index, ManyToOne, OneToMany, OptionalProps, PrimaryKeyProp, Property, Ref } from '@mikro-orm/core'; @@ -1105,8 +1212,11 @@ export class ProductSellers { } ", - "import { Collection, Entity, OneToMany, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; +import { Countries } from './Countries'; +import { ProductCountryMap } from './ProductCountryMap'; import { ProductSellers } from './ProductSellers'; +import { Sellers } from './Sellers'; @Entity() export class Products { @@ -1128,9 +1238,15 @@ export class Products { @Property({ default: 0 }) currentQuantity: number = 0; + @ManyToMany({ entity: () => Countries, pivotTable: 'product_country_map', pivotEntity: () => ProductCountryMap, joinColumn: 'product_id', inverseJoinColumn: 'country' }) + productCountryMap = new Collection(this); + @OneToMany({ entity: () => ProductSellers, mappedBy: 'product' }) productInverse = new Collection(this); + @ManyToMany({ entity: () => Sellers, mappedBy: 'productSellers' }) + productSellersInverse = new Collection(this); + } ", "import { Entity, Index, ManyToOne, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Ref } from '@mikro-orm/core'; @@ -1171,8 +1287,9 @@ export class Sales { } ", - "import { Collection, Entity, OneToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; @Entity() export class Sellers { @@ -1186,6 +1303,9 @@ export class Sellers { @Property({ length: 255 }) name!: string; + @ManyToMany({ entity: () => Products, pivotTable: 'product_sellers', pivotEntity: () => ProductSellers, joinColumn: 'seller_id', inverseJoinColumn: 'product_id' }) + productSellers = new Collection(this); + @OneToMany({ entity: () => ProductSellers, mappedBy: 'seller' }) sellerInverse = new Collection(this); @@ -1198,11 +1318,13 @@ exports[`overlap_fk_example scalarPropertiesForRelations=always bidirectionalRel [ "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; export class Countries { [PrimaryKeyProp]?: 'code'; code!: unknown; countriesInverse = new Collection(this); + productCountryMapInverse = new Collection(this); } export const CountriesSchema = new EntitySchema({ @@ -1210,6 +1332,7 @@ export const CountriesSchema = new EntitySchema({ properties: { code: { primary: true, type: 'unknown', columnType: 'char(2)' }, countriesInverse: { kind: '1:m', entity: () => ProductCountryMap, mappedBy: 'countries' }, + productCountryMapInverse: { kind: 'm:n', entity: () => Products, mappedBy: 'productCountryMap' }, }, }); ", @@ -1300,7 +1423,9 @@ export const ProductSellersSchema = new EntitySchema({ }); ", "import { Collection, EntitySchema, OptionalProps, PrimaryKeyProp } from '@mikro-orm/core'; +import { Countries } from './Countries'; import { ProductSellers } from './ProductSellers'; +import { Sellers } from './Sellers'; export class Products { [PrimaryKeyProp]?: 'productId'; @@ -1309,7 +1434,9 @@ export class Products { name!: string; currentPrice!: string; currentQuantity: number = 0; + productCountryMap = new Collection(this); productInverse = new Collection(this); + productSellersInverse = new Collection(this); } export const ProductsSchema = new EntitySchema({ @@ -1319,7 +1446,16 @@ export const ProductsSchema = new EntitySchema({ name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, currentPrice: { type: 'string', columnType: 'numeric(10,2)' }, currentQuantity: { type: 'number', default: 0 }, + productCountryMap: { + kind: 'm:n', + entity: () => Countries, + pivotTable: 'product_country_map', + pivotEntity: () => ProductCountryMap, + joinColumn: 'product_id', + inverseJoinColumn: 'country', + }, productInverse: { kind: '1:m', entity: () => ProductSellers, mappedBy: 'product' }, + productSellersInverse: { kind: 'm:n', entity: () => Sellers, mappedBy: 'productSellers' }, }, }); ", @@ -1376,11 +1512,13 @@ export const SalesSchema = new EntitySchema({ ", "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; export class Sellers { [PrimaryKeyProp]?: 'sellerId'; sellerId!: number; name!: string; + productSellers = new Collection(this); sellerInverse = new Collection(this); } @@ -1389,6 +1527,14 @@ export const SellersSchema = new EntitySchema({ properties: { sellerId: { primary: true, type: 'number' }, name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, + productSellers: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_sellers', + pivotEntity: () => ProductSellers, + joinColumn: 'seller_id', + inverseJoinColumn: 'product_id', + }, sellerInverse: { kind: '1:m', entity: () => ProductSellers, mappedBy: 'seller' }, }, }); @@ -1398,7 +1544,9 @@ export const SellersSchema = new EntitySchema({ exports[`overlap_fk_example scalarPropertiesForRelations=never bidirectionalRelations=false identifiedReferences=false entitySchema=false: dump 1`] = ` [ - "import { Entity, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; +import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; @Entity() export class Countries { @@ -1408,6 +1556,9 @@ export class Countries { @PrimaryKey({ columnType: 'char(2)' }) code!: unknown; + @ManyToMany({ entity: () => Products, pivotTable: 'product_country_map', pivotEntity: () => ProductCountryMap, joinColumn: 'country', inverseJoinColumn: 'product_id' }) + productCountryMap = new Collection(this); + } ", "import { Entity, ManyToOne, OptionalProps, PrimaryKeyProp, Property } from '@mikro-orm/core'; @@ -1507,7 +1658,9 @@ export class Sales { } ", - "import { Entity, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; +import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; @Entity() export class Sellers { @@ -1521,6 +1674,9 @@ export class Sellers { @Property({ length: 255 }) name!: string; + @ManyToMany({ entity: () => Products, pivotTable: 'product_sellers', pivotEntity: () => ProductSellers, joinColumn: 'seller_id', inverseJoinColumn: 'product_id' }) + productSellers = new Collection(this); + } ", ] @@ -1528,17 +1684,27 @@ export class Sellers { exports[`overlap_fk_example scalarPropertiesForRelations=never bidirectionalRelations=false identifiedReferences=false entitySchema=true: dump 1`] = ` [ - "import { EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; +import { Products } from './Products'; export class Countries { [PrimaryKeyProp]?: 'code'; code!: unknown; + productCountryMap = new Collection(this); } export const CountriesSchema = new EntitySchema({ class: Countries, properties: { code: { primary: true, type: 'unknown', columnType: 'char(2)' }, + productCountryMap: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_country_map', + pivotEntity: () => ProductCountryMap, + joinColumn: 'country', + inverseJoinColumn: 'product_id', + }, }, }); ", @@ -1666,12 +1832,14 @@ export const SalesSchema = new EntitySchema({ }, }); ", - "import { EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; +import { Products } from './Products'; export class Sellers { [PrimaryKeyProp]?: 'sellerId'; sellerId!: number; name!: string; + productSellers = new Collection(this); } export const SellersSchema = new EntitySchema({ @@ -1679,6 +1847,14 @@ export const SellersSchema = new EntitySchema({ properties: { sellerId: { primary: true, type: 'number' }, name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, + productSellers: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_sellers', + pivotEntity: () => ProductSellers, + joinColumn: 'seller_id', + inverseJoinColumn: 'product_id', + }, }, }); ", @@ -1687,7 +1863,9 @@ export const SellersSchema = new EntitySchema({ exports[`overlap_fk_example scalarPropertiesForRelations=never bidirectionalRelations=false identifiedReferences=true entitySchema=false: dump 1`] = ` [ - "import { Entity, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; +import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; @Entity() export class Countries { @@ -1697,6 +1875,9 @@ export class Countries { @PrimaryKey({ columnType: 'char(2)' }) code!: unknown; + @ManyToMany({ entity: () => Products, pivotTable: 'product_country_map', pivotEntity: () => ProductCountryMap, joinColumn: 'country', inverseJoinColumn: 'product_id' }) + productCountryMap = new Collection(this); + } ", "import { Entity, ManyToOne, OptionalProps, PrimaryKeyProp, Property, Ref } from '@mikro-orm/core'; @@ -1796,7 +1977,9 @@ export class Sales { } ", - "import { Entity, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; +import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; @Entity() export class Sellers { @@ -1810,6 +1993,9 @@ export class Sellers { @Property({ length: 255 }) name!: string; + @ManyToMany({ entity: () => Products, pivotTable: 'product_sellers', pivotEntity: () => ProductSellers, joinColumn: 'seller_id', inverseJoinColumn: 'product_id' }) + productSellers = new Collection(this); + } ", ] @@ -1817,17 +2003,27 @@ export class Sellers { exports[`overlap_fk_example scalarPropertiesForRelations=never bidirectionalRelations=false identifiedReferences=true entitySchema=true: dump 1`] = ` [ - "import { EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; +import { Products } from './Products'; export class Countries { [PrimaryKeyProp]?: 'code'; code!: unknown; + productCountryMap = new Collection(this); } export const CountriesSchema = new EntitySchema({ class: Countries, properties: { code: { primary: true, type: 'unknown', columnType: 'char(2)' }, + productCountryMap: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_country_map', + pivotEntity: () => ProductCountryMap, + joinColumn: 'country', + inverseJoinColumn: 'product_id', + }, }, }); ", @@ -1972,12 +2168,14 @@ export const SalesSchema = new EntitySchema({ }, }); ", - "import { EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; +import { Products } from './Products'; export class Sellers { [PrimaryKeyProp]?: 'sellerId'; sellerId!: number; name!: string; + productSellers = new Collection(this); } export const SellersSchema = new EntitySchema({ @@ -1985,6 +2183,14 @@ export const SellersSchema = new EntitySchema({ properties: { sellerId: { primary: true, type: 'number' }, name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, + productSellers: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_sellers', + pivotEntity: () => ProductSellers, + joinColumn: 'seller_id', + inverseJoinColumn: 'product_id', + }, }, }); ", @@ -1993,8 +2199,9 @@ export const SellersSchema = new EntitySchema({ exports[`overlap_fk_example scalarPropertiesForRelations=never bidirectionalRelations=true identifiedReferences=false entitySchema=false: dump 1`] = ` [ - "import { Collection, Entity, OneToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; @Entity() export class Countries { @@ -2004,6 +2211,9 @@ export class Countries { @PrimaryKey({ columnType: 'char(2)' }) code!: unknown; + @ManyToMany({ entity: () => Products, pivotTable: 'product_country_map', pivotEntity: () => ProductCountryMap, joinColumn: 'country', inverseJoinColumn: 'product_id' }) + productCountryMap = new Collection(this); + @OneToMany({ entity: () => ProductCountryMap, mappedBy: 'country' }) countryInverse = new Collection(this); @@ -2061,8 +2271,10 @@ export class ProductSellers { } ", - "import { Collection, Entity, OneToMany, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; +import { Countries } from './Countries'; import { ProductSellers } from './ProductSellers'; +import { Sellers } from './Sellers'; @Entity() export class Products { @@ -2084,9 +2296,15 @@ export class Products { @Property({ default: 0 }) currentQuantity: number = 0; + @ManyToMany({ entity: () => Countries, mappedBy: 'productCountryMap' }) + productCountryMapInverse = new Collection(this); + @OneToMany({ entity: () => ProductSellers, mappedBy: 'product' }) productInverse = new Collection(this); + @ManyToMany({ entity: () => Sellers, mappedBy: 'productSellers' }) + productSellersInverse = new Collection(this); + } ", "import { Entity, Index, ManyToOne, OptionalProps, PrimaryKey, PrimaryKeyProp, Property } from '@mikro-orm/core'; @@ -2118,8 +2336,9 @@ export class Sales { } ", - "import { Collection, Entity, OneToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; @Entity() export class Sellers { @@ -2133,6 +2352,9 @@ export class Sellers { @Property({ length: 255 }) name!: string; + @ManyToMany({ entity: () => Products, pivotTable: 'product_sellers', pivotEntity: () => ProductSellers, joinColumn: 'seller_id', inverseJoinColumn: 'product_id' }) + productSellers = new Collection(this); + @OneToMany({ entity: () => ProductSellers, mappedBy: 'seller' }) sellerInverse = new Collection(this); @@ -2145,10 +2367,12 @@ exports[`overlap_fk_example scalarPropertiesForRelations=never bidirectionalRela [ "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; export class Countries { [PrimaryKeyProp]?: 'code'; code!: unknown; + productCountryMap = new Collection(this); countryInverse = new Collection(this); } @@ -2156,6 +2380,14 @@ export const CountriesSchema = new EntitySchema({ class: Countries, properties: { code: { primary: true, type: 'unknown', columnType: 'char(2)' }, + productCountryMap: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_country_map', + pivotEntity: () => ProductCountryMap, + joinColumn: 'country', + inverseJoinColumn: 'product_id', + }, countryInverse: { kind: '1:m', entity: () => ProductCountryMap, mappedBy: 'country' }, }, }); @@ -2226,7 +2458,9 @@ export const ProductSellersSchema = new EntitySchema({ }); ", "import { Collection, EntitySchema, OptionalProps, PrimaryKeyProp } from '@mikro-orm/core'; +import { Countries } from './Countries'; import { ProductSellers } from './ProductSellers'; +import { Sellers } from './Sellers'; export class Products { [PrimaryKeyProp]?: 'productId'; @@ -2235,7 +2469,9 @@ export class Products { name!: string; currentPrice!: string; currentQuantity: number = 0; + productCountryMapInverse = new Collection(this); productInverse = new Collection(this); + productSellersInverse = new Collection(this); } export const ProductsSchema = new EntitySchema({ @@ -2245,7 +2481,9 @@ export const ProductsSchema = new EntitySchema({ name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, currentPrice: { type: 'string', columnType: 'numeric(10,2)' }, currentQuantity: { type: 'number', default: 0 }, + productCountryMapInverse: { kind: 'm:n', entity: () => Countries, mappedBy: 'productCountryMap' }, productInverse: { kind: '1:m', entity: () => ProductSellers, mappedBy: 'product' }, + productSellersInverse: { kind: 'm:n', entity: () => Sellers, mappedBy: 'productSellers' }, }, }); ", @@ -2295,11 +2533,13 @@ export const SalesSchema = new EntitySchema({ ", "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; export class Sellers { [PrimaryKeyProp]?: 'sellerId'; sellerId!: number; name!: string; + productSellers = new Collection(this); sellerInverse = new Collection(this); } @@ -2308,6 +2548,14 @@ export const SellersSchema = new EntitySchema({ properties: { sellerId: { primary: true, type: 'number' }, name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, + productSellers: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_sellers', + pivotEntity: () => ProductSellers, + joinColumn: 'seller_id', + inverseJoinColumn: 'product_id', + }, sellerInverse: { kind: '1:m', entity: () => ProductSellers, mappedBy: 'seller' }, }, }); @@ -2317,8 +2565,9 @@ export const SellersSchema = new EntitySchema({ exports[`overlap_fk_example scalarPropertiesForRelations=never bidirectionalRelations=true identifiedReferences=true entitySchema=false: dump 1`] = ` [ - "import { Collection, Entity, OneToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; @Entity() export class Countries { @@ -2328,6 +2577,9 @@ export class Countries { @PrimaryKey({ columnType: 'char(2)' }) code!: unknown; + @ManyToMany({ entity: () => Products, pivotTable: 'product_country_map', pivotEntity: () => ProductCountryMap, joinColumn: 'country', inverseJoinColumn: 'product_id' }) + productCountryMap = new Collection(this); + @OneToMany({ entity: () => ProductCountryMap, mappedBy: 'country' }) countryInverse = new Collection(this); @@ -2385,8 +2637,10 @@ export class ProductSellers { } ", - "import { Collection, Entity, OneToMany, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; +import { Countries } from './Countries'; import { ProductSellers } from './ProductSellers'; +import { Sellers } from './Sellers'; @Entity() export class Products { @@ -2408,9 +2662,15 @@ export class Products { @Property({ default: 0 }) currentQuantity: number = 0; + @ManyToMany({ entity: () => Countries, mappedBy: 'productCountryMap' }) + productCountryMapInverse = new Collection(this); + @OneToMany({ entity: () => ProductSellers, mappedBy: 'product' }) productInverse = new Collection(this); + @ManyToMany({ entity: () => Sellers, mappedBy: 'productSellers' }) + productSellersInverse = new Collection(this); + } ", "import { Entity, Index, ManyToOne, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Ref } from '@mikro-orm/core'; @@ -2442,8 +2702,9 @@ export class Sales { } ", - "import { Collection, Entity, OneToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; @Entity() export class Sellers { @@ -2457,6 +2718,9 @@ export class Sellers { @Property({ length: 255 }) name!: string; + @ManyToMany({ entity: () => Products, pivotTable: 'product_sellers', pivotEntity: () => ProductSellers, joinColumn: 'seller_id', inverseJoinColumn: 'product_id' }) + productSellers = new Collection(this); + @OneToMany({ entity: () => ProductSellers, mappedBy: 'seller' }) sellerInverse = new Collection(this); @@ -2469,10 +2733,12 @@ exports[`overlap_fk_example scalarPropertiesForRelations=never bidirectionalRela [ "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; export class Countries { [PrimaryKeyProp]?: 'code'; code!: unknown; + productCountryMap = new Collection(this); countryInverse = new Collection(this); } @@ -2480,6 +2746,14 @@ export const CountriesSchema = new EntitySchema({ class: Countries, properties: { code: { primary: true, type: 'unknown', columnType: 'char(2)' }, + productCountryMap: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_country_map', + pivotEntity: () => ProductCountryMap, + joinColumn: 'country', + inverseJoinColumn: 'product_id', + }, countryInverse: { kind: '1:m', entity: () => ProductCountryMap, mappedBy: 'country' }, }, }); @@ -2563,7 +2837,9 @@ export const ProductSellersSchema = new EntitySchema({ }); ", "import { Collection, EntitySchema, OptionalProps, PrimaryKeyProp } from '@mikro-orm/core'; +import { Countries } from './Countries'; import { ProductSellers } from './ProductSellers'; +import { Sellers } from './Sellers'; export class Products { [PrimaryKeyProp]?: 'productId'; @@ -2572,7 +2848,9 @@ export class Products { name!: string; currentPrice!: string; currentQuantity: number = 0; + productCountryMapInverse = new Collection(this); productInverse = new Collection(this); + productSellersInverse = new Collection(this); } export const ProductsSchema = new EntitySchema({ @@ -2582,7 +2860,9 @@ export const ProductsSchema = new EntitySchema({ name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, currentPrice: { type: 'string', columnType: 'numeric(10,2)' }, currentQuantity: { type: 'number', default: 0 }, + productCountryMapInverse: { kind: 'm:n', entity: () => Countries, mappedBy: 'productCountryMap' }, productInverse: { kind: '1:m', entity: () => ProductSellers, mappedBy: 'product' }, + productSellersInverse: { kind: 'm:n', entity: () => Sellers, mappedBy: 'productSellers' }, }, }); ", @@ -2636,11 +2916,13 @@ export const SalesSchema = new EntitySchema({ ", "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; export class Sellers { [PrimaryKeyProp]?: 'sellerId'; sellerId!: number; name!: string; + productSellers = new Collection(this); sellerInverse = new Collection(this); } @@ -2649,6 +2931,14 @@ export const SellersSchema = new EntitySchema({ properties: { sellerId: { primary: true, type: 'number' }, name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, + productSellers: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_sellers', + pivotEntity: () => ProductSellers, + joinColumn: 'seller_id', + inverseJoinColumn: 'product_id', + }, sellerInverse: { kind: '1:m', entity: () => ProductSellers, mappedBy: 'seller' }, }, }); @@ -2658,7 +2948,9 @@ export const SellersSchema = new EntitySchema({ exports[`overlap_fk_example scalarPropertiesForRelations=smart bidirectionalRelations=false identifiedReferences=false entitySchema=false: dump 1`] = ` [ - "import { Entity, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; +import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; @Entity() export class Countries { @@ -2668,6 +2960,9 @@ export class Countries { @PrimaryKey({ columnType: 'char(2)' }) code!: unknown; + @ManyToMany({ entity: () => Products, pivotTable: 'product_country_map', pivotEntity: () => ProductCountryMap, joinColumn: 'country', inverseJoinColumn: 'product_id' }) + productCountryMap = new Collection(this); + } ", "import { Entity, ManyToOne, OptionalProps, PrimaryKeyProp, Property } from '@mikro-orm/core'; @@ -2767,7 +3062,9 @@ export class Sales { } ", - "import { Entity, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; +import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; @Entity() export class Sellers { @@ -2781,6 +3078,9 @@ export class Sellers { @Property({ length: 255 }) name!: string; + @ManyToMany({ entity: () => Products, pivotTable: 'product_sellers', pivotEntity: () => ProductSellers, joinColumn: 'seller_id', inverseJoinColumn: 'product_id' }) + productSellers = new Collection(this); + } ", ] @@ -2788,17 +3088,27 @@ export class Sellers { exports[`overlap_fk_example scalarPropertiesForRelations=smart bidirectionalRelations=false identifiedReferences=false entitySchema=true: dump 1`] = ` [ - "import { EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; +import { Products } from './Products'; export class Countries { [PrimaryKeyProp]?: 'code'; code!: unknown; + productCountryMap = new Collection(this); } export const CountriesSchema = new EntitySchema({ class: Countries, properties: { code: { primary: true, type: 'unknown', columnType: 'char(2)' }, + productCountryMap: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_country_map', + pivotEntity: () => ProductCountryMap, + joinColumn: 'country', + inverseJoinColumn: 'product_id', + }, }, }); ", @@ -2926,12 +3236,14 @@ export const SalesSchema = new EntitySchema({ }, }); ", - "import { EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; +import { Products } from './Products'; export class Sellers { [PrimaryKeyProp]?: 'sellerId'; sellerId!: number; name!: string; + productSellers = new Collection(this); } export const SellersSchema = new EntitySchema({ @@ -2939,6 +3251,14 @@ export const SellersSchema = new EntitySchema({ properties: { sellerId: { primary: true, type: 'number' }, name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, + productSellers: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_sellers', + pivotEntity: () => ProductSellers, + joinColumn: 'seller_id', + inverseJoinColumn: 'product_id', + }, }, }); ", @@ -2947,7 +3267,9 @@ export const SellersSchema = new EntitySchema({ exports[`overlap_fk_example scalarPropertiesForRelations=smart bidirectionalRelations=false identifiedReferences=true entitySchema=false: dump 1`] = ` [ - "import { Entity, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; +import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; @Entity() export class Countries { @@ -2957,6 +3279,9 @@ export class Countries { @PrimaryKey({ columnType: 'char(2)' }) code!: unknown; + @ManyToMany({ entity: () => Products, pivotTable: 'product_country_map', pivotEntity: () => ProductCountryMap, joinColumn: 'country', inverseJoinColumn: 'product_id' }) + productCountryMap = new Collection(this); + } ", "import { Entity, ManyToOne, OptionalProps, PrimaryKeyProp, Property, Ref } from '@mikro-orm/core'; @@ -3056,7 +3381,9 @@ export class Sales { } ", - "import { Entity, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; +import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; @Entity() export class Sellers { @@ -3070,6 +3397,9 @@ export class Sellers { @Property({ length: 255 }) name!: string; + @ManyToMany({ entity: () => Products, pivotTable: 'product_sellers', pivotEntity: () => ProductSellers, joinColumn: 'seller_id', inverseJoinColumn: 'product_id' }) + productSellers = new Collection(this); + } ", ] @@ -3077,17 +3407,27 @@ export class Sellers { exports[`overlap_fk_example scalarPropertiesForRelations=smart bidirectionalRelations=false identifiedReferences=true entitySchema=true: dump 1`] = ` [ - "import { EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; +import { Products } from './Products'; export class Countries { [PrimaryKeyProp]?: 'code'; code!: unknown; + productCountryMap = new Collection(this); } export const CountriesSchema = new EntitySchema({ class: Countries, properties: { code: { primary: true, type: 'unknown', columnType: 'char(2)' }, + productCountryMap: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_country_map', + pivotEntity: () => ProductCountryMap, + joinColumn: 'country', + inverseJoinColumn: 'product_id', + }, }, }); ", @@ -3232,12 +3572,14 @@ export const SalesSchema = new EntitySchema({ }, }); ", - "import { EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; +import { Products } from './Products'; export class Sellers { [PrimaryKeyProp]?: 'sellerId'; sellerId!: number; name!: string; + productSellers = new Collection(this); } export const SellersSchema = new EntitySchema({ @@ -3245,6 +3587,14 @@ export const SellersSchema = new EntitySchema({ properties: { sellerId: { primary: true, type: 'number' }, name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, + productSellers: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_sellers', + pivotEntity: () => ProductSellers, + joinColumn: 'seller_id', + inverseJoinColumn: 'product_id', + }, }, }); ", @@ -3253,8 +3603,9 @@ export const SellersSchema = new EntitySchema({ exports[`overlap_fk_example scalarPropertiesForRelations=smart bidirectionalRelations=true identifiedReferences=false entitySchema=false: dump 1`] = ` [ - "import { Collection, Entity, OneToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; @Entity() export class Countries { @@ -3264,6 +3615,9 @@ export class Countries { @PrimaryKey({ columnType: 'char(2)' }) code!: unknown; + @ManyToMany({ entity: () => Products, pivotTable: 'product_country_map', pivotEntity: () => ProductCountryMap, joinColumn: 'country', inverseJoinColumn: 'product_id' }) + productCountryMap = new Collection(this); + @OneToMany({ entity: () => ProductCountryMap, mappedBy: 'country' }) countryInverse = new Collection(this); @@ -3321,8 +3675,10 @@ export class ProductSellers { } ", - "import { Collection, Entity, OneToMany, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; +import { Countries } from './Countries'; import { ProductSellers } from './ProductSellers'; +import { Sellers } from './Sellers'; @Entity() export class Products { @@ -3344,9 +3700,15 @@ export class Products { @Property({ default: 0 }) currentQuantity: number = 0; + @ManyToMany({ entity: () => Countries, mappedBy: 'productCountryMap' }) + productCountryMapInverse = new Collection(this); + @OneToMany({ entity: () => ProductSellers, mappedBy: 'product' }) productInverse = new Collection(this); + @ManyToMany({ entity: () => Sellers, mappedBy: 'productSellers' }) + productSellersInverse = new Collection(this); + } ", "import { Entity, Index, ManyToOne, OptionalProps, PrimaryKey, PrimaryKeyProp, Property } from '@mikro-orm/core'; @@ -3378,8 +3740,9 @@ export class Sales { } ", - "import { Collection, Entity, OneToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; @Entity() export class Sellers { @@ -3393,6 +3756,9 @@ export class Sellers { @Property({ length: 255 }) name!: string; + @ManyToMany({ entity: () => Products, pivotTable: 'product_sellers', pivotEntity: () => ProductSellers, joinColumn: 'seller_id', inverseJoinColumn: 'product_id' }) + productSellers = new Collection(this); + @OneToMany({ entity: () => ProductSellers, mappedBy: 'seller' }) sellerInverse = new Collection(this); @@ -3405,10 +3771,12 @@ exports[`overlap_fk_example scalarPropertiesForRelations=smart bidirectionalRela [ "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; export class Countries { [PrimaryKeyProp]?: 'code'; code!: unknown; + productCountryMap = new Collection(this); countryInverse = new Collection(this); } @@ -3416,6 +3784,14 @@ export const CountriesSchema = new EntitySchema({ class: Countries, properties: { code: { primary: true, type: 'unknown', columnType: 'char(2)' }, + productCountryMap: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_country_map', + pivotEntity: () => ProductCountryMap, + joinColumn: 'country', + inverseJoinColumn: 'product_id', + }, countryInverse: { kind: '1:m', entity: () => ProductCountryMap, mappedBy: 'country' }, }, }); @@ -3486,7 +3862,9 @@ export const ProductSellersSchema = new EntitySchema({ }); ", "import { Collection, EntitySchema, OptionalProps, PrimaryKeyProp } from '@mikro-orm/core'; +import { Countries } from './Countries'; import { ProductSellers } from './ProductSellers'; +import { Sellers } from './Sellers'; export class Products { [PrimaryKeyProp]?: 'productId'; @@ -3495,7 +3873,9 @@ export class Products { name!: string; currentPrice!: string; currentQuantity: number = 0; + productCountryMapInverse = new Collection(this); productInverse = new Collection(this); + productSellersInverse = new Collection(this); } export const ProductsSchema = new EntitySchema({ @@ -3505,7 +3885,9 @@ export const ProductsSchema = new EntitySchema({ name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, currentPrice: { type: 'string', columnType: 'numeric(10,2)' }, currentQuantity: { type: 'number', default: 0 }, + productCountryMapInverse: { kind: 'm:n', entity: () => Countries, mappedBy: 'productCountryMap' }, productInverse: { kind: '1:m', entity: () => ProductSellers, mappedBy: 'product' }, + productSellersInverse: { kind: 'm:n', entity: () => Sellers, mappedBy: 'productSellers' }, }, }); ", @@ -3555,11 +3937,13 @@ export const SalesSchema = new EntitySchema({ ", "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; export class Sellers { [PrimaryKeyProp]?: 'sellerId'; sellerId!: number; name!: string; + productSellers = new Collection(this); sellerInverse = new Collection(this); } @@ -3568,6 +3952,14 @@ export const SellersSchema = new EntitySchema({ properties: { sellerId: { primary: true, type: 'number' }, name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, + productSellers: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_sellers', + pivotEntity: () => ProductSellers, + joinColumn: 'seller_id', + inverseJoinColumn: 'product_id', + }, sellerInverse: { kind: '1:m', entity: () => ProductSellers, mappedBy: 'seller' }, }, }); @@ -3577,8 +3969,9 @@ export const SellersSchema = new EntitySchema({ exports[`overlap_fk_example scalarPropertiesForRelations=smart bidirectionalRelations=true identifiedReferences=true entitySchema=false: dump 1`] = ` [ - "import { Collection, Entity, OneToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; @Entity() export class Countries { @@ -3588,6 +3981,9 @@ export class Countries { @PrimaryKey({ columnType: 'char(2)' }) code!: unknown; + @ManyToMany({ entity: () => Products, pivotTable: 'product_country_map', pivotEntity: () => ProductCountryMap, joinColumn: 'country', inverseJoinColumn: 'product_id' }) + productCountryMap = new Collection(this); + @OneToMany({ entity: () => ProductCountryMap, mappedBy: 'country' }) countryInverse = new Collection(this); @@ -3645,8 +4041,10 @@ export class ProductSellers { } ", - "import { Collection, Entity, OneToMany, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; +import { Countries } from './Countries'; import { ProductSellers } from './ProductSellers'; +import { Sellers } from './Sellers'; @Entity() export class Products { @@ -3668,9 +4066,15 @@ export class Products { @Property({ default: 0 }) currentQuantity: number = 0; + @ManyToMany({ entity: () => Countries, mappedBy: 'productCountryMap' }) + productCountryMapInverse = new Collection(this); + @OneToMany({ entity: () => ProductSellers, mappedBy: 'product' }) productInverse = new Collection(this); + @ManyToMany({ entity: () => Sellers, mappedBy: 'productSellers' }) + productSellersInverse = new Collection(this); + } ", "import { Entity, Index, ManyToOne, OptionalProps, PrimaryKey, PrimaryKeyProp, Property, Ref } from '@mikro-orm/core'; @@ -3702,8 +4106,9 @@ export class Sales { } ", - "import { Collection, Entity, OneToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToMany, PrimaryKey, PrimaryKeyProp, Property, Unique } from '@mikro-orm/core'; import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; @Entity() export class Sellers { @@ -3717,6 +4122,9 @@ export class Sellers { @Property({ length: 255 }) name!: string; + @ManyToMany({ entity: () => Products, pivotTable: 'product_sellers', pivotEntity: () => ProductSellers, joinColumn: 'seller_id', inverseJoinColumn: 'product_id' }) + productSellers = new Collection(this); + @OneToMany({ entity: () => ProductSellers, mappedBy: 'seller' }) sellerInverse = new Collection(this); @@ -3729,10 +4137,12 @@ exports[`overlap_fk_example scalarPropertiesForRelations=smart bidirectionalRela [ "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductCountryMap } from './ProductCountryMap'; +import { Products } from './Products'; export class Countries { [PrimaryKeyProp]?: 'code'; code!: unknown; + productCountryMap = new Collection(this); countryInverse = new Collection(this); } @@ -3740,6 +4150,14 @@ export const CountriesSchema = new EntitySchema({ class: Countries, properties: { code: { primary: true, type: 'unknown', columnType: 'char(2)' }, + productCountryMap: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_country_map', + pivotEntity: () => ProductCountryMap, + joinColumn: 'country', + inverseJoinColumn: 'product_id', + }, countryInverse: { kind: '1:m', entity: () => ProductCountryMap, mappedBy: 'country' }, }, }); @@ -3823,7 +4241,9 @@ export const ProductSellersSchema = new EntitySchema({ }); ", "import { Collection, EntitySchema, OptionalProps, PrimaryKeyProp } from '@mikro-orm/core'; +import { Countries } from './Countries'; import { ProductSellers } from './ProductSellers'; +import { Sellers } from './Sellers'; export class Products { [PrimaryKeyProp]?: 'productId'; @@ -3832,7 +4252,9 @@ export class Products { name!: string; currentPrice!: string; currentQuantity: number = 0; + productCountryMapInverse = new Collection(this); productInverse = new Collection(this); + productSellersInverse = new Collection(this); } export const ProductsSchema = new EntitySchema({ @@ -3842,7 +4264,9 @@ export const ProductsSchema = new EntitySchema({ name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, currentPrice: { type: 'string', columnType: 'numeric(10,2)' }, currentQuantity: { type: 'number', default: 0 }, + productCountryMapInverse: { kind: 'm:n', entity: () => Countries, mappedBy: 'productCountryMap' }, productInverse: { kind: '1:m', entity: () => ProductSellers, mappedBy: 'product' }, + productSellersInverse: { kind: 'm:n', entity: () => Sellers, mappedBy: 'productSellers' }, }, }); ", @@ -3896,11 +4320,13 @@ export const SalesSchema = new EntitySchema({ ", "import { Collection, EntitySchema, PrimaryKeyProp } from '@mikro-orm/core'; import { ProductSellers } from './ProductSellers'; +import { Products } from './Products'; export class Sellers { [PrimaryKeyProp]?: 'sellerId'; sellerId!: number; name!: string; + productSellers = new Collection(this); sellerInverse = new Collection(this); } @@ -3909,6 +4335,14 @@ export const SellersSchema = new EntitySchema({ properties: { sellerId: { primary: true, type: 'number' }, name: { type: 'string', length: 255, unique: 'name_UNIQUE' }, + productSellers: { + kind: 'm:n', + entity: () => Products, + pivotTable: 'product_sellers', + pivotEntity: () => ProductSellers, + joinColumn: 'seller_id', + inverseJoinColumn: 'product_id', + }, sellerInverse: { kind: '1:m', entity: () => ProductSellers, mappedBy: 'seller' }, }, }); diff --git a/tests/features/entity-generator/__snapshots__/ScalarPropsForFks.mysql.test.ts.snap b/tests/features/entity-generator/__snapshots__/ScalarPropsForFks.mysql.test.ts.snap index a305d493c695..45c9dee179b2 100644 --- a/tests/features/entity-generator/__snapshots__/ScalarPropsForFks.mysql.test.ts.snap +++ b/tests/features/entity-generator/__snapshots__/ScalarPropsForFks.mysql.test.ts.snap @@ -317,8 +317,9 @@ export class Dummy2 { } ", - "import { Entity, OneToOne, OptionalProps, PrimaryKey, Property, Unique } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToOne, OptionalProps, PrimaryKey, Property, Unique } from '@mikro-orm/core'; import { FooBaz2 } from './FooBaz2'; +import { FooParam2 } from './FooParam2'; @Entity() export class FooBar2 { @@ -363,6 +364,9 @@ export class FooBar2 { @Property({ columnType: 'json', nullable: true }) objectProperty?: any; + @ManyToMany({ entity: () => FooBaz2, pivotTable: 'foo_param2', pivotEntity: () => FooParam2, joinColumn: 'bar_id', inverseJoinColumn: 'baz_id' }) + fooParam2 = new Collection(this); + } ", "import { Entity, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; @@ -871,8 +875,9 @@ export class Dummy2 { } ", - "import { Entity, OneToOne, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; + "import { Collection, Entity, ManyToMany, OneToOne, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core'; import { FooBaz2 } from './FooBaz2'; +import { FooParam2 } from './FooParam2'; @Entity() export class FooBar2 { @@ -909,6 +914,9 @@ export class FooBar2 { @Property({ columnType: 'json', nullable: true }) objectProperty?: any; + @ManyToMany({ entity: () => FooBaz2, pivotTable: 'foo_param2', pivotEntity: () => FooParam2, joinColumn: 'bar_id', inverseJoinColumn: 'baz_id' }) + fooParam2 = new Collection(this); + } ", "import { Entity, OptionalProps, PrimaryKey, Property } from '@mikro-orm/core';