question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modeling relation that doesn't follow naming strategy

See original GitHub issue

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);

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
emrosenfcommented, Jan 23, 2020

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.

0reactions
emrosenfcommented, Mar 23, 2020

I brought the definitions to the subclass level and it’s working. Thanks for everything.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Naming Conventions in Database Modeling - Vertabelo
Database models require that objects be named. While several facets of naming an object deserve consideration, in this article we'll focus ...
Read more >
ActiveRecord Naming Conventions and How to Alias Around ...
A model name is singular and uses CamelCase — the corresponding table uses snake_case and is pluralized using Ruby's pluralize method so you...
Read more >
Naming Strategies - Sequelize
Naming Strategies. The underscored option​. Sequelize provides the underscored option for a model. When true , this option will set the field option...
Read more >
Are there conventions for naming 'through' models in Django
Django has some very clear conventions for naming models: do so in the singular; describe the object the model represents ...
Read more >
Fluent API - Relationships - EF6 - Microsoft Learn
Fluent API - Relationships in Entity Framework 6. ... Foreign Key Name That Does Not Follow the Code First Convention; Model Used in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found