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
update_attribute returns unexpected nil when new value is the same as current #26593
Comments
If there is no change in the database why true is expected?
|
Because I don't care what happens behind (in db) or what was the previous value. |
In fact the return of this method should not care for you. If you are And yes nil is false in that case and it means exactly what it means, no
|
I am not expecting always You mean that what with If instead there can be a |
Of course if the I still think that Maybe I just need to replace |
@rafaelfranca @donapieppo I had changed this behavior to save a SQL call in 0fcd4cf5. I think we can return true if |
a Otherwise the doc should say that |
👍
|
Great, I will send a PR in some time. |
- If the attribute is not changed, then update_attribute does not run SQL query, this effectively means that no change was made to the attribute. - This change was made in rails@0fcd4cf5 to avoid a SQL call. - But the change resulted into `nil` being returned when there was no change in the attribute value. - This commit corrects the behavior to return true if there is no change in attribute value. This is same as previous behavior of Rails 4.2 plus benefit of no additional SQL call. - Fixes rails#26593.
- If the attribute is not changed, then update_attribute does not run SQL query, this effectively means that no change was made to the attribute. - This change was made in 0fcd4cf5 to avoid a SQL call. - But the change resulted into `nil` being returned when there was no change in the attribute value. - This commit corrects the behavior to return true if there is no change in attribute value. This is same as previous behavior of Rails 4.2 plus benefit of no additional SQL call. - Fixes #26593.
- If the attribute is not changed, then update_attribute does not run SQL query, this effectively means that no change was made to the attribute. - This change was made in rails/rails@0fcd4cf to avoid a SQL call. - But the change resulted into `nil` being returned when there was no change in the attribute value. - This commit corrects the behavior to return true if there is no change in attribute value. This is same as previous behavior of Rails 4.2 plus benefit of no additional SQL call. - Fixes rails#26593.
update_attribute(name, value)
returnsnil
if the submitted value is the same as the current value.In rails 4 it returned
true
(as aspected, imo).I think in rails 4 the db update query was always done.
In rails 5 the unecessary update is skipped but I think the return value should be
true
.With
update_column
the update is done and the return value is alwaystrue
.Expected behavior
System configuration
Rails: 5.0.0.1
Ruby: 2.3.1p112
The text was updated successfully, but these errors were encountered: