Hi, let me explain the problem :)
You have a one-to-many relation (for exemple books can have one store and stores can have multiple books).
Now you have $book1 linked to $store1 (storeId in book table references book.id).
When I need to remove that link WITHOUT removing the book, I have 2 options (both doesnt work correctly).
Etiher I'm doing:
$books = $store1->getBooks();
//Here I delete the book from the collection
In that case, setBooks will add $book1 to booksScheduledForDeletion collection, wich will cause his deletion when save() is done.
But in that case, the $store1->getBooks() wont be updated if I dont do $store1->reload(true);
Furthermore, event if solution 2 was working, it wouldnt be elegant for me to do it that way, since I'm finding it confusing to get/add the books from store object and remove one from book.
So in my opinion, it would be great, if you could set a parameter (either in the schema.xml or directly in the setBooks() function) to disable the ScheduledForDeletion line.
Yes it should be doable to add a parameter in the setter method.
Just a reflexion, this is most likelly linked with database foreign key. I mean, if in your table, the foreign key is mandatory (NOT NULL), you have to delete the related element when you remove the relation. But when it's not, you should just remove the relation without deleting the related element.
So in that case, it would be more a change in the code generated by the schema.
Actually, it should probably rely on the ON DELETE constraint: