active-record
active-record copied to clipboard
AR beforeSave attributes
It would be nice to know, what attributes are going to be saved in beforeSave method. If you have some logic, which fires before saving particular attribute, that logic will fire even if you called save specifiying some other attributes. You may have this attribute locally changed, so checking isAttributeChanged
is not an option. This will complement afterSave changedAttributes logic and as I saw, it won't be very hard to implement this.
What steps will reproduce the problem?
Create AR with some attributes including name
and status
Add some code in AR beforeSave
method, which does something with status
attribute
Change status
and name
attributes locally
Call save(true, ['name'])
. (Do not include your attribute to save)
What is the expected result?
You know, that status will not be saved and act accordingly
What do you get instead?
You don't know, what attributes will be saved
Additional info
Q | A |
---|---|
Yii version | 2.0.13 |
PHP version | 7 |
Operating system | any |
717d0e8 is not closing this issue.
Yes, it wasn't about this issue. The number 15358 I got from PR number because there wasn't an issue for this PR.
Changing it in 2.0 would break current behavior. Moving to 2.1.