mikro-orm: Modeling relation that doesn't follow naming strategy

My application follow the EntityCaseNamingStrategy and I don’t wish to change that.

There are two tables that I didn’t design and I would like to accommodate.

Basically Account has many AccountSegments. Here is the abridged DDL

CREATE TABLE "Account" (
    "accountNumber" text PRIMARY KEY,
    ...
);

CREATE TABLE "AccountSegment" (
    "segmentId" text PRIMARY KEY,
    "accountNumber" text,
    ...
);

What options do I have to pass to @ManyToOne and @OneToMany to accommodate this? I’ve been trying with no luck along the lines of:


  @ManyToOne(() => Account, { inversedBy: 'segments', })
  account?: IdentifiedReference<Account>;

  ...

  @OneToMany(() => AccountSegment, segment => segment.account, { referenceColumnName: 'accountNumber', })
  segments = new Collection<AccountSegment>(this);

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (9 by maintainers)

Most upvoted comments

That’s not actually the source of the error.

Screen Shot 2020-01-23 at 8 05 43 AM

The problem is that meta.primaryKey is “accountNumber” but in the entity (owning side of 1:m), the field has been renamed to account.