Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

HStore Field not initialized as Hash #90

Open
frugardc opened this issue Feb 21, 2013 · 5 comments
Open

HStore Field not initialized as Hash #90

frugardc opened this issue Feb 21, 2013 · 5 comments

Comments

@frugardc
Copy link

Installed as directed, column comes up as hstore in my pg database after migration run, but the column is not initialized as a hash. MRI 1.9.3, Rails 3.2.6

class MaintenanceNotification < ActiveRecord::Base
    serialize :data, ActiveRecord::Coders::Hstore
    attr_accessible :circuit_id, :customer, :data, :maintenance_id,:sent,:start_time,:end_time

m = MaintenanceNotification.new
 => #<MaintenanceNotification id: nil, data: nil, circuit_id: nil, maintenance_id: nil,      customer: nil, sent: nil, start_time: nil, end_time: nil, created_at: nil, updated_at: nil> 
    1.9.3p194 :002 > m.data
 => nil 
@mockdeep
Copy link

Yeah, thought this commit changed it, but no such luck: 0b66d8b

@mockdeep
Copy link

Also tried adding execute("ALTER TABLE students ALTER COLUMN data SET DEFAULT hstore(array[]::varchar[])") to my migration, but it's still nil. From here: #22

@mockdeep
Copy link

Adding serialize :data, ActiveRecord::Coders::Hstore to my model fixed this.

@frugardc
Copy link
Author

The default was not added for me as part of the migrate script. I ran manually on the db to see if that fixed the issue. Doesn't seem to have.

@mockdeep
Copy link

Yeah, it doesn't add it to the database. The serializer assigns an empty hash to it on the fly.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants