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)
That’s not actually the source of the error.
The problem is that
meta.primaryKeyis “accountNumber” but in theentity(owning side of 1:m), the field has been renamed toaccount.