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

Introduce support for alias attributes #799

Merged

Conversation

leonidkroka
Copy link
Contributor

@leonidkroka leonidkroka commented May 10, 2023

Probably it's related to issues:
#728:

class MyModel < ActiveRecord::Base
  alias_attribute :foo, :baz
end

MyModel.import(%i[foo bar], %w[value_foo value_baz], validate: false, on_duplicate_key_update: { conflict_target: %i[bar], columns: %i[foo] })

#795:

class MyModel < ActiveRecord::Base
  self.ignored_columns = [:bar]
end

MyModel.import(%i[foo bar], %w[value_foo value_baz], validate: false, on_duplicate_key_ignore: true)
MyModel.import(%i[foo bar], %w[value_foo value_baz], validate: false, on_duplicate_key_update: { conflict_target: %i[foo], columns: %i[bar] })

@jkowens
Copy link
Collaborator

jkowens commented May 10, 2023

Awesome, thank you for this update! 🎉

@jkowens jkowens merged commit 367a177 into zdennis:master May 10, 2023
11 of 12 checks passed
@jkowens
Copy link
Collaborator

jkowens commented May 10, 2023

@leonidkroka I missed that that 4.2 specs had a failure. I'm ok with dropping support for AR 4.2 if necessary. Should we go that route or can that be resolved easily?

@leonidkroka
Copy link
Contributor Author

leonidkroka commented May 10, 2023

@jkowens thank you for your support in fast applying changes
AR 4.2 has quite a different approach to building columns_hash, so would say it would be difficult to prepare a proper fix to fit AB 4.2 and newer versions at the same time.
Well, it's possible to go with if-else condition:

if respond_to?(:ignored_columns) && ignored_columns.any?
  connection.schema_cache.columns_hash(table_name)
else
  columns_hash
end

Have just opened the respective PR #800 (will rerun tests tomorrow)

Yeap, that doesn't look like a cool solution, so it's up to you to use that fix or drop support for AR 4.2

@jkowens
Copy link
Collaborator

jkowens commented Aug 21, 2023

Finally released in v1.5.0 🎉

Comment on lines +967 to +970
def schema_columns_hash
load_schema unless schema_loaded?
@schema_columns_hash ||= connection.schema_cache.columns_hash(table_name)
end

Choose a reason for hiding this comment

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

@leonidkroka @jkowens

I think the @schema_columns_hash should be cleared by .reset_column_information.

👉 #809

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants