Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Problem with cascade delete
I have 3 models.
Quiz HAS MANY Question
Question BELONGS TO Quiz and HAS MANY Reponses
Reponse BELONGS TO Question
In the edit treatment, i put all Questions of the Quiz in $oldQuestions
I do some code, and i put all new Questions in the Quiz
If ($quiz->save()) work, i want delete $oldQuestions because they are orphelans
All old Questions are deleted, but not their Reponses. I have set "cascade_delete" => true in the relationship.
Here is the code :
The edit action :
cascade delete only runs a delete on fetched relations, it iterates over the objects and calls delete() on them, it does not run a delete query.
So if you want to delete responses too, make sure they are fetched:
$quiz = Model_Quiz::find($id, array('related' => array('question', 'question.response')));
This has recently been changed in 1.7:
If you're on 1.6, you might want to backport this fix.
Ok, it's work fine, thanks
Add a Comment
It looks like you're new here. If you want to get involved, click one of these buttons!
Apply for Membership
↳ Job Board
↳ Installation & Setup
↳ Tips and Tutorials
↳ Code share
In this Discussion