feat: register store_attributes as attributes
Enables better compatibility with other gems (i.e. StoreModel) which rely on attributes being registered on the model.
Checklist
- [x] I've added tests for this change
- [x] I've added a Changelog entry
- NOT NEEDED - I've updated a documentation (Readme)
Enables better compatibility with other gems (i.e. StoreModel)
Could you please provide an example of when it could be useful?
I'm a bit concerned of potential incompatibilities, and in general it's questionable whether we should consider store attributes to be real attributes. I don't know. Maybe, we should make this feature optional and off by default.
Enables better compatibility with other gems (i.e. StoreModel)
Could you please provide an example of when it could be useful?
I'm a bit concerned of potential incompatibilities, and in general it's questionable whether we should consider store attributes to be real attributes. I don't know. Maybe, we should make this feature optional and off by default.
An example is that I would like to store enums as json attributes.
I'd also very much like to be able to query on these attributes, fwiw.
Hey cool, this is exactly what I need. Right now we are using https://github.com/madeintandem/jsonb_accessor, but we need to move away from it because it's not longer maintained.
We are iterating over all attributes on a model in order to do some token replacement in text.
page.attributes.each do |attr|
find_and_replace_tokens
end
That's my use case for needed data attributes to respond as attributes.
Thanks!
@hmasing @Petercopter Thanks for the details!
Let's then proceed with this feature but make it opt-in for now; we can added a setting similar to store_attribute_unset_values_fallback_to_default:
class Post < ApplicationRecord
self.store_attribute_register_attributes = true
store_attribute :extra, :published_at, :datetime
end
Post.new.attributes.include?("published_at") #=> true
@RickCSong Will you be able to add this change? If not I (or, maybe, someone else) can pick up from here, no worries. Thank you!
Hey @palkan you haven't done this right? @RickCSong is a buddy and we can find someone to add the change you suggested!
Hey @4ndypanda,
you haven't done this right?
Right. Feel free to pick up the PR!
Hey @4ndypanda,
you haven't done this right?
Right. Feel free to pick up the PR!
Hey @palkan the @RickCSong added the change you suggested to the PR - this is ready for rereview let us know if there's any other changes you need