mikro-orm: Migration missing pivot table creation for ManyToMany

Describe the bug I have two tables that I just added ManyToMany relations to and for some reason the migration created doesn’t have anything for the pivot table… not sure if this is a bug or if I’m doing something dumb 😬

Stack trace N/A

To Reproduce


// ProviderBusiness.ts
@ManyToMany(() => Service, 'providers', { owner: true })
services = new Collection<Service>(this);

// Service.ts
@ManyToMany(() => ProviderBusiness, (providerBusiness) => providerBusiness.services)
providers = new Collection<ProviderBusiness>(this);

After making those changes and running yarn mikro-orm migration:create nothing gets generated for the pivot table.

Expected behavior The new migration contains commands to create the pivot table

Additional context I’ve tried practically every variation of syntax and read through the docs pretty thoroughly, so not sure what the issue is. I also checked to make sure the files being detected were showing up correctly. My only other path forward would be to try this.

Versions

Dependency Version
node v16.13.0
typescript 4.4.3
mikro-orm 4.5.9
@mikro-orm/postgresql 4.5.9

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (21 by maintainers)

Most upvoted comments

Compare the code, they might do almost the same thing, you could as well just extend the mongo strategy and implement that missing method.

class MyNS extends MongoNamingStrategy {
  joinTableName(sourceEntity: string, targetEntity: string, propertyName: string): string {
    return this.classToTableName(sourceEntity) + '_' + this.propertyToColumnName(propertyName);
  }
}

yarn add @mikro-orm/core@rc or specify the version explicitly if you want latest dev version (you will need to pin it, as ranges would install the RC instead of latest dev, because… NPM is dumb and ignores the dist tags, and rc is technically > than dev, so its “later version”) - so yarn add @mikro-orm/core@5.0.0-dev.692.

(you can see latest version in the versions tab here https://www.npmjs.com/package/@mikro-orm/core)

example app migrated to v5 rc: https://github.com/mikro-orm/nestjs-realworld-example-app

You might be better of using EntityCaseNamingStrategy.

https://github.com/mikro-orm/mikro-orm/blob/master/packages/core/src/naming-strategy/EntityCaseNamingStrategy.ts

I’ll implement that method for v5 just for the added safety (although this is kind of a misusage). No plans to backport anything at this stage as v5 is almost ready.

I see we don’t have the same idea of how minimal repro should look like 😛

Your property definition is ok, but this is not enough to reproduce anything. There are dozens of tests that test exactly this, try to prepare full reproduction.