store_attribute icon indicating copy to clipboard operation
store_attribute copied to clipboard

feat: register store_attributes as attributes

Open RickCSong opened this issue 2 years ago • 4 comments

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)

RickCSong avatar Jan 07 '23 03:01 RickCSong

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.

palkan avatar Jan 10 '23 17:01 palkan

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.

hmasing avatar Jan 17 '24 11:01 hmasing

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!

Petercopter avatar Mar 28 '24 17:03 Petercopter

@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!

palkan avatar Apr 18 '24 21:04 palkan

Hey @palkan you haven't done this right? @RickCSong is a buddy and we can find someone to add the change you suggested!

4ndypanda avatar Apr 23 '25 01:04 4ndypanda

Hey @4ndypanda,

you haven't done this right?

Right. Feel free to pick up the PR!

palkan avatar Apr 28 '25 18:04 palkan

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

n-ivan avatar May 07 '25 18:05 n-ivan