Monday, November 2, 2015

run Model::beforeSave before Behavior::beforeSave

Hi,

Is there any way to ensure that Model::beforeSave runs before Behavior::beforeSave?

My use case is saving multiple records into a model with Tree behaviour, where the scope can change from record to record.

So, using Model::beforeSave I check to see if the scope field has a value and if so I set the Tree scope to that value.  

Problem is Tree::beforeSave has already ran and set the lft and rght values not taking the correct scope into account.

I can get around this be manually calling the following in Model::beforeSave right after setting the scope ...

$this->Behaviors->Tree->beforeSave($this);

... but this feels really hacky.

Any ideas on how I control the order/priority of beforeSave actions?

Thanks, Paul.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: