Thank you all for your help, There were many good suggestions, some of
which helped optimize my code.
However the bug boiled down to something stupid (of course). I created
my the association for my ProjectTask model wrong in my Schedule
model. It should *not* have been pluralized. Not sure why
Try putting:
$this-ProjectTasks-create();
in each loop of the foreach in Schedule::afterSave()
When you call save() multiple times on the same model, I have found
that I run into problems if I don't call create() in between each call
to save().
On Apr 17, 3:00 pm, Joshua McFarren [EMAIL
What I would do to verify this behavior is to debug the model itself
(Cake library). Just copy the original to a second file for safe keeping
and start digging. I would step debug statements through the save()
method and see if I could determine whether the beforeSave is called.
Looking at
It is quite a mystery, because if you look at the Model's save()
function, it clearly should be making a call to beforeSave():
http://api.cakephp.org/1.2/libs_2model_2model_8php-source.html#l01106
Have you tried deleting all the files that have accumulated in my app/
tmp/cache directory.
I dug a bit deeper and found this buried in the save:
if (!empty($joined) $success === true) {
$this-__saveMulti($joined, $this-id);
}
What this does is prior to the main record save, an array called $joined is
populated with your relationships from the calling model (I believe it was
Hi,
Is there a case where Model::save() doesn't initiate the beforeSave
and afterSave callbacks for that Model? Maybe this doesn't work from
another afterSave callback? Are these callbacks only initiated when
Model::save() is accessed from a Controller not another Model?
I have a Schedule Model
Hi Aran,
Thanks for the advice. Unfortunately I tried that and it doesn't make
a difference. The syntax i tried is:
$this-ProjectTasks-create();
$this-ProjectTasks-save($task);
In either case the save method does update the row in the DB but the
callbacks don't happen.
Any other ideas?
-