Skip to content

Setting a parameter to remove ScheduledForDeletion behavior #331

Open
Zekia opened this Issue Apr 4, 2012 · 3 comments

2 participants

@Zekia
Zekia commented Apr 4, 2012

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
....
$store1->clearBooks();
$store1->setBooks($books);
$store1->save();
In that case, setBooks will add $book1 to booksScheduledForDeletion collection, wich will cause his deletion when save() is done.

Other solution:
$book1->setStore(null);
$book1->save();
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.

Regards

@willdurand
Propel member

Yes it should be doable to add a parameter in the setter method.

@Zekia
Zekia commented May 2, 2012

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.
Regards.

@willdurand
Propel member

Actually, it should probably rely on the ON DELETE constraint:

  • CASCADE will delete the related object (current behavior);
  • SET NULL will just set null to the foreign key column.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.