-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Closed
Labels
Description
Issue Description
cascade save fails if the child entity has CreateDateColumn and PK as JoinColumn
Expected Behavior
No error
Actual Behavior
Error: Cannot update entity because entity id is not set in the entity.
When
- parent entity's PK is a generated column
- child entity's PK is a JoinColumn. (sharing PK)
- child entity has special columns that require re-select (like
CreateDateColumn) - save parent and child by cascade
It fails. TypeORM doesn't get the child entity id from the parent entity's PK.
Steps to Reproduce
@Entity()
export class Bar {
@PrimaryGeneratedColumn("increment")
id: number;
@Column()
title: string;
@OneToOne(() => Foo, foo => foo.bar, { cascade: true, eager: true })
foo: Foo;
}
@Entity()
export class Foo {
@PrimaryColumn()
id: number;
@Column()
text: string;
@OneToOne(() => Bar, b => b.foo, { primary: true })
@JoinColumn({ name: "id", referencedColumnName: "id" })
bar: Bar;
@CreateDateColumn()
d: Date;
}
// failing
await connection.manager.save(
connection.getRepository(Bar).create({
title: "bar",
foo: { text: "foo" }
})
);My Environment
| Dependency | Version |
|---|---|
| Operating System | |
| Node.js version | v10.20.1 |
| Typescript version | v3.6.5 |
| TypeORM version | v0.2.28 |
Additional Context
Relevant Database Driver(s)
-
aurora-data-api -
aurora-data-api-pg -
better-sqlite3 -
cockroachdb -
cordova -
expo -
mongodb -
mysql -
nativescript -
oracle -
postgres -
react-native -
sap -
sqlite -
sqlite-abstract -
sqljs -
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time, and I know how to start.
- Yes, I have the time, but I don't know how to start. I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Reactions are currently unavailable