-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't modify related model's data in beforeSave when using saveAll #1765
Comments
7th May 2010, Mark Story said: Its a feature, as currently saveAll only lets you use beforeSave to modify the record that's about to be saved, not the full data set. I personally don't feel that should change, but its something that could be discussed. |
7th May 2010, kennethfrey (at gmail) said: Thanks for responding Mark. I don't mind modifying the related data in its own beforeSave i.e. doing the logic in the Comment's beforeSave but when you do that you don't have access to the rest (the Post's data) of this->data. Am I incorrect about that? |
7th May 2010, Mark Story said: Don't assign tickets to me please. But yes, you won't have access to all of the data being processed by saveAll. You will have any primary keys for the parent record, so you could access the data that way. |
@markstory I guess you still feel the same about this. |
This is actually implemented in 3.0. The existing implementation of |
Created by kennethfrey (at gmail), 5th May 2010. (originally Lighthouse ticket #671):
Post hasMany Comment. Comment belongsTo Post.
$this->data = array(
'Post' => array(
'title' => 'mytitle',
'text' => 'mytext')
'Comment' => array(
0 => array('text' => 'mytext'),
1 => array('text' => 'mytext')
)
)
I am trying to use saveAll($this->data, array('validate' => 'first')) to save a Post and a multiple Comments. I am trying to modify $this->data['Comment'][0]['text'] to a different value. I can set it and debug just before returning true in beforeSave and the data looks correct.
I remove the debug let it save and it doesn't get set. I can change the data from the Comment model beforeSave but then the rest of $this->data isn't available and I need the other information in order to change the value how I want it. Is this a bug or feature?
The text was updated successfully, but these errors were encountered: