Skip to content
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

Unbreak update_column/update_columns for the primary key attribute. #8053

Merged

Conversation

henrik
Copy link
Contributor

@henrik henrik commented Oct 28, 2012

Didn't work before because it updated the model-in-memory first, so the DB query couldn't find the record.

@@ -224,11 +224,11 @@ def update_columns(attributes)
verify_readonly_attribute(key.to_s)
end

self.class.where(self.class.primary_key => id).update_all(attributes) == 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is modifying the return value of update_column. We should probably add a test to ensure it returns a boolean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I just noticed this. Should I go ahead and fix? Any preference between amend/force push vs. multiple commits in a feature branch?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally we prefer commits to be squashed, so amend/force push.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, pushed an amended commit: henrik@cd0efa5

Just tested that it returns true. Good enough? Seems the return value is undocumented anyway, and I'm not sure what it'd take to make it return false. Multiple records with the same id or for the query to somehow update nothing.

@carlosantoniodasilva
Copy link
Member

@henrik I think it's "the query updating nothing", in any case, it's just better to not change the result value to avoid possible breakage (and it'd be weird to return the attributes enumerable anyways). I made small comments, but overall it looks good, thanks!

@carlosantoniodasilva
Copy link
Member

@henrik thanks. Github says it cannot be merged anymore, can you rebase it from master please? It's probably the changelog.

@carlosantoniodasilva
Copy link
Member

And since you're touching the changelog, how about using backticks like this instead of \ escaping: "update_columns and update_column"

@rafaelfranca
Copy link
Member

Do you mean this? update_column and update_column

@carlosantoniodasilva
Copy link
Member

Yes.

@henrik
Copy link
Contributor Author

henrik commented Oct 28, 2012

Good idea - used backticks, rebased against master.

@henrik
Copy link
Contributor Author

henrik commented Oct 28, 2012

Oops, a merge commit snuck in there. Fixing.

Didn't work before because it updated the model-in-memory first, so the DB query couldn't find the record.
@henrik
Copy link
Contributor Author

henrik commented Oct 28, 2012

And there we go.

@rafaelfranca
Copy link
Member

@carlosantoniodasilva :shipit:

carlosantoniodasilva added a commit that referenced this pull request Oct 28, 2012
Unbreak update_column/update_columns for the primary key attribute.
@carlosantoniodasilva carlosantoniodasilva merged commit c6f47c1 into rails:master Oct 28, 2012
@carlosantoniodasilva
Copy link
Member

@henrik awesome, thanks.

@henrik
Copy link
Contributor Author

henrik commented Oct 28, 2012

Wow, that was faster and less ceremony than expected. Thanks a lot, guys!

@rafaelfranca
Copy link
Member

Thank you

carlosantoniodasilva added a commit that referenced this pull request Oct 29, 2012
Unbreak update_column/update_columns for the primary key attribute.
Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/persistence.rb
	activerecord/test/cases/persistence_test.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants