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.

get a relation key for side of OneToOne

See original GitHub issue

Issue type: [X ] question Database system/driver: [X ] mysql / mariadb TypeORM version: [X ] latest

How now it is possible to find out from which column they are related?

I performed a search I need links

getRepository (this.constructor) .metadata.findRelationWithPropertyPath ('l10n');

Expected Result: id_category

@Entity("categories", {})
export class CategoriesModel extends ORM {

    @OneToOne(type => L10nCategoriesModel, l10n => l10n.categories, {
        eager: true,
        cascadeInsert: true,
        cascadeUpdate: true,
        cascadeRemove: true,
        onDelete: 'CASCADE'
    })
    l10n: L10nCategoriesModel[];

}

@Entity("l10n-categories", {})
export class L10nCategoriesModel extends ORM {

    /* id_category */
    @OneToOne(type => CategoriesModel, category => category.l10n, {
        onDelete: 'CASCADE'
    })
    @JoinColumn({
        name: 'id_category',
    })
    categories: CategoriesModel;
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pleerockcommented, Feb 15, 2018

You can do it only from the owner side of the relationship this way:

@Entity("l10n-categories", {})
export class L10nCategoriesModel extends ORM {

    @OneToOne(type => CategoriesModel, category => category.l10n)
    @JoinColumn({ name: 'id_category' })
    category: CategoriesModel;

    @Column({ name: 'id_category' })
    categoryId: number;
}
0reactions
Flexiinkcommented, Feb 15, 2018

Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

One-to-one relations - typeorm - GitBook
One-to-one is a relation where A contains only one instance of B, and B contains only one instance of A. Let's take for...
Read more >
The best way to map a @OneToOne relationship with JPA and ...
The best way to map a @OneToOne relationship is to use @MapsId . This way, you don't even need a bidirectional association since...
Read more >
Choose owning side in OneToOne relation
The fix for this problem is simple. You just change the owning side and inverse side. Make the User entity the owning entity....
Read more >
One-to-One Relationship in JPA - Baeldung
Learn three different ways to maintain a one-to-one relationship ... we only need it on the owning side of the foreign key relationship....
Read more >
node.js - TypeORM OneToOne Relation Joined by Primary Key
After @PrimaryColumn add @OneToOne relation to the main table ... give you a single column for the Primary Key and the Foreign Key...
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