Not working properly: One-to-many relation in a Embedded entity inside Single Table Inheritance
See original GitHub issueIssue type:
[x] bug report
Database system/driver:
[x] mssql
TypeORM version:
[x] latest
Steps to reproduce or a small repository showing the problem:
git clone https://github.com/cesarve77/typeorm-bug
cd typeorm-bug
git checkout Embedded
npm i
npm run start
Entities:
@ChildEntity()
export class Guest extends Member {
@Column()
cars: number
}
@Entity()
@TableInheritance({column: {name: "type", type: "varchar"}})
export class Member {
@PrimaryGeneratedColumn()
id: number;
@Column(type => BlueCard)
blueCard: BlueCard
@Column("varchar",{length: 50})
name: string
@Column("varchar",{length: 50})
surname: string
}
export class BlueCard {
@ManyToOne(type=>BlueCardStatus, blueCardStatus=>blueCardStatus.members, {eager: true})
status: BlueCardStatus;
@Column("text", {nullable: true,})
notes: Date;
constructor(init?: Partial<BlueCard>) {
Object.assign(this, init);
}
}
@Entity()
export class BlueCardStatus {
@PrimaryGeneratedColumn()
id: number;
@Column("varchar", {length: 50})
status: string
@OneToMany(type => Member, member => member.blueCard && member.blueCard.status)
members: Member[]
}
Expecting behaviour:
when:
const guest: Guest = new Guest()
const parent: Parent = new Parent()
parent.lots=12
parent.name='name1'
parent.surname='surname1'
parent.blueCard=new BlueCard()
parent.blueCard.status=new BlueCardStatus()
parent.blueCard.status.status='status 1'
guest.cars=1
guest.name='name2'
guest.surname='surname2'
guest.blueCard=new BlueCard()
guest.blueCard.status=new BlueCardStatus()
guest.blueCard.status.status='status 2'
await connection.manager.save(parent.blueCard.status)
await connection.manager.save(guest.blueCard.status)
await connection.manager.save(parent)
Everything saved (and it is saved but not related)
and the table looks like:
Result:
The status relation is not saved and status field in members is saves as statusId and not as blueCardStatusId
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:7 (2 by maintainers)
Top Results From Across the Web
java - Insert fails for @OneToMany Hibernate mapping with ...
I'm using Java and Hibernate 3.6.4.Final. TABLE_B is a mapping table for a specific type of A entities (B) which have a OneToMany...
Read more >The best way to map a @OneToMany relationship with JPA ...
The @ManyToOne annotation allows you to map the Foreign Key column in the child entity mapping so that the child has an entity...
Read more >Single Table Inheritance Strategy - JPA + Hibernate - LogicBig
In this strategy, all the classes in a hierarchy are mapped to a single table. The annotation @Inheritance is used on the root...
Read more >Mapping a Single Entity to Multiple Tables in JPA - Baeldung
The most obvious solution is to create an entity for both classes. We can see that meal_id is both the primary key and...
Read more >Inheritance Mapping - Doctrine Object Relational Mapper (ORM)
This means that One-To-Many associations are not possible on a mapped superclass at all. Furthermore Many-To-Many associations are only possible if the mapped ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
having the saving issue here as well, even without the table inheritance. just by having a relation inside the embedded entiy
Is this issue still open?? I continue having this issue.