active-record icon indicating copy to clipboard operation
active-record copied to clipboard

AR beforeSave attributes

Open gooverdian opened this issue 7 years ago • 3 comments

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

gooverdian avatar Dec 14 '17 08:12 gooverdian

717d0e8 is not closing this issue.

gooverdian avatar Dec 18 '17 07:12 gooverdian

Yes, it wasn't about this issue. The number 15358 I got from PR number because there wasn't an issue for this PR.

developeruz avatar Dec 18 '17 07:12 developeruz

Changing it in 2.0 would break current behavior. Moving to 2.1.

samdark avatar Dec 18 '17 22:12 samdark