This project is archived and is in readonly mode.
Unexpected side effect of update_attribute implementation change on associations and attributes
-
Neeraj Singh
- Milestone set to 3.x
- Tag set to rails 3, activerecord
- Assigned user set to Neeraj Singh
- Importance changed from to Low
-
Neeraj Singh
- State changed from new to wontfix
The commit also mentions a change where updated_at doesn't change with update_attribute, does that pose any issues for anyone else or is it just me?
updated_at/on will always change. I am not able to see where in commit message I mentioned that updated_at/on will not change.
The idea behind update_attribute is that user should be pretty much assured that update_attribute changes the field in the database. That is why validation and callbacks are not called so that no one can prevent the update to the database.
case 1
self.update_attribute(:account, Account.create)Above case is not supported and that is okay. That case can be changed to
self.update_attribute(:account_id, Account.create.id)case 2
@task.update_attribute(:complete_note, "Foo Bar")In the above case only database change should take place is to change updated_at/on. And for that you can simply do
@task.touchI understand that update_attribute would be used in a lot lesser number of cases and that is the intent. update_attributes should be used in majority of cases and update_attribute should be limited to a few cases where you want to update a field. For example after sending out an email. If a bug prevents marking that field as updated then user might get a number of emails delivered to him/her.
Discussed the issue with José Valim and he is okay with it.