[Feature][ActiveRecord] Add custom types to store_accessor

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Feature][ActiveRecord] Add custom types to store_accessor

Tiago Babo
Right now one can use the attributes API for custom types, but it doesn't work with store attributes. The following method would fix that:

store_accessor :preferences, :show_avatar, :boolean, default: true

I've implemented a concern with this logic for a project I'm working on, and it works great. 

Do you think it would be a nice addition to Rails?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Feature][ActiveRecord] Add custom types to store_accessor

Vlad Dem
Hey Tiago!

IMO, the feature could be a great addition to Rails. And the number of times it has been proposed kinda proves it:
- https://github.com/rails/rails/commit/85b64f98d100d37b3a232c315daa10fad37dccdc#commitcomment-650592 (the very early days of store accessors)
- https://github.com/rails/rails/pull/18942 (extracted into a gem store_attribute)
- https://github.com/rails/rails/pull/26882 (still open).

There is also another gem with a bit different API (https://github.com/byroot/activerecord-typedstore).

store_accessor :preferences, :show_avatar, :boolean, default: true

This API looks a bit confusing: how to distinguish between `boolean` as attribute name and as a type? I mean, the following code is valid in Rails:

store_accessor :preferences, :show_avatar, :boolean


On Monday, May 6, 2019 at 11:48:44 AM UTC-4, Tiago Babo wrote:
Right now one can use the attributes API for custom types, but it doesn't work with store attributes. The following method would fix that:

store_accessor :preferences, :show_avatar, :boolean, default: true

I've implemented a concern with this logic for a project I'm working on, and it works great. 

Do you think it would be a nice addition to Rails?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-core/774ad660-d9d4-4d6c-b900-5a6fde166250%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.