-
Notifications
You must be signed in to change notification settings - Fork 22k
ActiveStorage reflection #33018
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
ActiveStorage reflection #33018
Conversation
|
r? @sgrif (@rails-bot has picked a reviewer for you, use r? to override) |
|
I'm fine with a reflection API but we should follow the same interface and similar implementation of the association and aggregation reflection API. https://github.com/rails/rails/blob/375a4143cf5caeb6159b338be824903edfd62836/activerecord/lib/active_record/reflection.rb |
|
@rafaelfranca I updated it to hook into |
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 think we can do this without adding a new load hook to the public API. The class_attribute should be added to the ActiveRecord::Base class. The ReflectionExtensions can be added directly to ActiveRecord::Reflection without need a on_load hook.
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.
Sure that makes sense. I was just trying to keep the ActiveStorage stuff to itself, but happy to move it over.
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.
Why you need the :: here? Also keep everything in the same line.
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.
Top level constant just for the milliseconds it would shave off the constant lookup - I'll remove
Add the ability to reflect on the attachments that have been defined using ActiveRecord::Reflection.
|
@rafaelfranca updated once more |
rafaelfranca
left a comment
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 ok with this current implementation. Even that those reflections can only be added once you have active storage loaded I think it is fine to have the reflections always on Active Record.
I'd prefer to have it totally separated though, and it is possible to do without introducing new on_load hooks.
I'll check if other member of the team before implementing it.
@georgeclaghorn @matthewd options?
|
I’m okay with this implementation, too, but I’d prefer for it to live in Active Storage. |
|
I'd be happy to refactor, just wasn't sure how to hook it in up the engine to ensure |
|
Okay so refactored and this works. I can move these modules into ActiveRecord or leave them here, let me know which is preferable. |
rafaelfranca
left a comment
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.
Yeah, now it is better
| end | ||
| end | ||
|
|
||
| module ReflectionExtension |
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 think this one should be :nodoc: like all methods in Reflection are.
| end | ||
|
|
||
| module ReflectionExtension | ||
| def reflection_class_for(macro) |
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 method should be private
|
@rafaelfranca updated! |
|
Thanks! |
Add the ability to query for the attachments that have been defined on a model through the
ActiveRecord::Base::defined_attachmentsmethod.Useful for writing things on top of ActiveStorage that can loop through models and their attachments to perform things in bulk.