Skip to content

Remove missing child objects in a relation #1351

@timothyvanderaerden

Description

@timothyvanderaerden

Hello

I have a question where I cannot find the solution for in the documentation.

My Understanding is that when you use the .save() function, the foreign key of all all missing child objects will be set to null. Is there a 'nice' way to remove those objects from the database instead of setting the foreign key to null, using the save methode?

So for example if I have the following books in my database:

id name
1 Book x
2 Book y

And save the following object:

Author: {
   name: "...",
   books: [
       {
           name: "Book z",
       },
       {
            id: 2
            name: "Book yy",
       }
    ]
}
const authorRepository = getConnection('database').getRepository(Author);
await authorRepository.save(author);

The result should be:

id name
2 Book yy
3 Book z

I'm using version: 0.2.0-alpha.12.

Thanks

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions