Reputation: 1318
Ok, I have a weird one here. In a Rails 4.0.13 application, I've added to a model:
store_accessor :transcoding_meta, :state
Looking at the schema of the model (SongVersion), transcoding_meta
's type is indeed hstore
.
Note, there is also a state
column on SongVersion, which is a string column.
s = SongVersion.ready.last
s.transcoding_meta
=> {"state"=>"finished"}
s.state
=> "finished"
When in fact, the state column in the database is saved as "active"
as expected.
Why is Rails getting tripped up? Can I really not have an hstore
key with the same name as an existing column? Seems it should know the diff.
Upvotes: 3
Views: 76
Reputation: 23317
.store_accessor
is a macro that defines accessors for hstore fields. As it's called inside the class body, generated accesstors override ones for DB columns provided by default by ActiveRecord. It looks that you cannot have store field and column with the same name in a model.
Upvotes: 2