Re: Question about Model::save() and its beforeSave and afterSave callbacks

2008-04-24 Thread Joshua McFarren
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 i

Re: Question about Model::save() and its beforeSave and afterSave callbacks

2008-04-18 Thread Fred Hirsch
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

Re: Question about Model::save() and its beforeSave and afterSave callbacks

2008-04-18 Thread Joshua McFarren
> Have you tried deleting all the files that have accumulated in my app/ > tmp/cache directory.  Sometimes when I have had these kinds of strange > problems it was because of an outdated cached model file. Hi Aran, I deleted the cache and unfortunately that didn't help. I'm pretty sure the wrong

Re: Question about Model::save() and its beforeSave and afterSave callbacks

2008-04-18 Thread aranworld
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. Someti

Re: Question about Model::save() and its beforeSave and afterSave callbacks

2008-04-18 Thread Fred Hirsch
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 the

Re: Question about Model::save() and its beforeSave and afterSave callbacks

2008-04-18 Thread Joshua McFarren
Hi Fred, Thanks for your input. No, I was not overriding save anywhere and I dont have any beforeSave callbacks in my app_model yet. However you sparked an idea to override ProjectTask::save() to see if that's even being called and its not! class ProjectTask extends AppModel { var $name = 'P

Re: Question about Model::save() and its beforeSave and afterSave callbacks

2008-04-18 Thread aranworld
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 PR

Re: Question about Model::save() and its beforeSave and afterSave callbacks

2008-04-17 Thread Joshua McFarren
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? -

Question about Model::save() and its beforeSave and afterSave callbacks

2008-04-17 Thread Joshua McFarren
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