byroot / activerecord-typedstore

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

Attempting to assign a default to an array type does not work. #80

Closed lundie closed 11 months ago

lundie commented 4 years ago

Hi,

I am attempting the following:

class Member < ApplicationRecord

#  application_layout                :jsonb

typed_store :application_layout do |s|
    s.string :tabs, default: ["company_information", "company_history", "company_contacts", "company_references", "banking_information"], array:true, null: false
   s.string :page_title_en, default: "My Online Form"
end

Then running in the console:

m = Member.new
m.tabs
(which returns a blank array [])
m.pate_title_en 
(returns the title "My Online Form").

I can set the value of the array after the fact and it works.

Is there a way to default the values of the array?

Thanks :)

casperisfine commented 4 years ago

Weird, this should work. Sounds like a bug.

gilbert commented 4 years ago

Just ran into this bug too. It ignores my default: and initializes with an empty array instead.