madeintandem / hstore_accessor

Adds typed hstore-backed field support to ActiveRecord models.
MIT License
242 stars 47 forks source link

default values #7

Closed kirillsalykin closed 5 years ago

kirillsalykin commented 10 years ago

it should be possible to add default value, like hstore_accessor :settings, share_via_facebook: :boolean, default: false

thegrubbsian commented 10 years ago

I like this idea, it would be pretty useful. The only issue though is whether to store the default value in the database or just return it if that key hasn't been set. Thoughts?

kirillsalykin commented 10 years ago

just return it if that key hasn't been set

i guess this would be perfect

aaronchi commented 10 years ago

I would like this feature as well

pallymore commented 10 years ago

I was just thinking about this :) right now i'm just using a before_create hook on the model to set the default values.

aripollak commented 10 years ago

Could you use the default_value_for gem for this functionality?

cjjuice commented 9 years ago

+1 sitting on 193 keys 95% are strings lol

mockdeep commented 7 years ago

A default would be great. I could see setting it in the database, especially for boolean values. We have some that default to true, which means we make column_name != false comparisons in our code. This also has implications for the query methods:

> Product.is_popular
=> []
> Product.not_popular
=> []
> Product.count
=> 52