-
Notifications
You must be signed in to change notification settings - Fork 74
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
Expose attribute_aliases as attributes #565
base: master
Are you sure you want to change the base?
Conversation
# NOTE: CloudObjectStoreObject.alias_attribute :name, :key | ||
it "finds attributes aliases (without virtual attribute defined)" do | ||
# if this shows true, find another model/attribute | ||
expect(model.virtual_attribute?("name")).to eq(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little confused what this is trying to show. For CloudObjectStoreObject, both "key" and "name" show up in attribute_names, so I feel like this test would pass without the code changes above. Same goes for Flavor with "cpus" and "cpu_cores"
irb(main):009> Flavor.attribute_names[-2..]
=> ["cpus", "cpu_cores"]
irb(main):010> Flavor.attribute_aliases.keys
=> ["cpus", "cpu_cores"]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for rails 7.1.
irb(main):002:0> Flavor.attribute_names.grep(/cpu/)
=> ["cpu_total_cores", "cpu_cores_per_socket", "cpu_sockets"]
irb(main):003:0> Flavor.attribute_aliases.keys.grep(/cpu/)
=> ["cpus", "cpu_cores"]
I think it's related to https://www.github.com/rails/rails/pull/52117 and the issue that caused it: https://www.github.com/rails/rails/issues/52111.
Basically, we can't do virtual_attribute
on things that are aliased attributes. We're moving to just keeping alias_attribute
and removing the virtual_attribute
for aliased attributes. Therefore, we need to change automate to pull in aliased attributes since we can't rely on attributes/attribute_names to have them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the idea is to drop virtual_column or virtual_attribute on things that are aliased attributes, like this commit:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We hack it into attribute_names for virtual columns. This doesn't work with rails 7.1 for aliased attributes because they changed how they work in rails 7.1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok thanks - I couldn't understand the context - I knew it was Rails 7.1, but it didn't make sense.
b9aa202
to
6e92c8e
Compare
@@ -60,7 +60,7 @@ def self.ar_model_associations | |||
|
|||
def self.expose_class_attributes(subclass) | |||
subclass.class_eval do | |||
model.attribute_names.each do |attr| | |||
(model.attribute_names | model.try(:attribute_aliases)&.keys).each do |attr| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find on this location. Does it make sense to have method that virtual attributes adds that provides this?
I see we have similar code here and ManageIQ/manageiq-api#1278. Perhaps, we could have something in core that extends AR to give us exposed_attribute_names
so we can have one place to test that exposed_attribute_names
includes virtual attributes, columns, aliased attributes, etc. Perhaps deprecated_attributes are in the same bucket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrafanie Did you see my comment above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
No description provided.