byroot / activerecord-typedstore

ActiveRecord::Store but with type definition
MIT License
439 stars 57 forks source link

Setting default values to match an existing column #54

Closed joshforeman closed 7 years ago

joshforeman commented 7 years ago

How would I go about setting a default value to reference an existing column's value?

For example, I have a setting such as 'notification_email', where the default value should be the current value of the email column.

typed_store :settings, coder: DumbCoder do |s| s.string :notification_email, default: self.email, null: false end

I've tried self.email, email and a few other variants but I either get errors referencing to call connection on the related model, or that it email is an undefined method.

rafaelfranca commented 7 years ago

This is not supported currently. The default value can be only static values.

joshforeman commented 7 years ago

Thanks @rafaelfranca