Skip to content

save does not return generated id if object to save contains a many to one relationship with an undefined id #5520

@shusson

Description

@shusson

Issue type:

[X] bug report

Database system/driver:

[X] postgres

TypeORM version:

[X] 0.2.22

Steps to reproduce or a small repository showing the problem:

@Entity()
class Bean {
    @PrimaryGeneratedColumn("uuid") 
    readonly id: string;
    
    @Column()
    name: string

    @ManyToOne(() => Friend)
    friend?: Friend;
}


const green = new Bean();
green.name = "green";
const x = await getRepository(Bean).save(green);
// {id: "4a602d92-19f3-4c2f-93e5-922a4d907a75",  name: "green" }

const red = new Bean();
red.name = "red";
red.friend = {id: undefined} as Friend; 
const y = await getRepository(Bean).save(red);
// {name: "red" }

I would expect the id is always returned.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions