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

Fix ActiveRecord::Relation#touch_all with custom attribute aliased as attribute for update #51787

Merged

Conversation

fatkodima
Copy link
Member

If we have something like

create_table :users do |t|
  t.timestamp :legacy_updated_at
end

class User < ActiveRecord::Base
  alias_attribute :updated_at, :legacy_updated_at
end

User.touch_all(:updated_at)

then ActiveRecord will not resolve updated_at to its alias correctly and result to a query that updates the same column twice.

For PostgreSQL, this produces an error similar to this:

ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR:  multiple assignments to same column "legacy_updated_at"

@kamipo kamipo merged commit 3688594 into rails:main May 13, 2024
3 of 4 checks passed
rafaelfranca pushed a commit that referenced this pull request May 13, 2024
…ttribute-for-update

Fix `ActiveRecord::Relation#touch_all` with custom attribute aliased as attribute for update
rafaelfranca pushed a commit that referenced this pull request May 13, 2024
…ttribute-for-update

Fix `ActiveRecord::Relation#touch_all` with custom attribute aliased as attribute for update
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.

None yet

2 participants