Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Orm
Problem with cascade delete
Syntaxlb
June 2013
Hi,
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 :
Model_Quiz :
http://bin.fuelphp.com/~h0
Model_Question :
http://bin.fuelphp.com/~hY
Model_Reponse :
http://bin.fuelphp.com/~hZ
The edit action :
http://bin.fuelphp.com/~h1
Harro
June 2013
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')));
$quiz->delete();
This has recently been changed in 1.7:
https://github.com/fuel/orm/commit/dcc815e06a5a319154b9c16bb059276d2a1266d2
If you're on 1.6, you might want to backport this fix.
Syntaxlb
June 2013
Ok, it's work fine, thanks
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
June 2013
Syntaxlb
June 2013