Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Latest commit

 

History

History
24 lines (15 loc) · 543 Bytes

README.md

File metadata and controls

24 lines (15 loc) · 543 Bytes

Enable Postgres HStore column serialization for your ActiveRecord / Rails 3.1+ project.

Huge thanks and credit to https://github.com/softa/activerecord-postgres-hstore for code and inspiration.

Example

class Car < ActiveRecord::Base
  serialize :data, HstoreSerializer
end

toyota = Car.create(:data => {:doors => 2, :color => "grey"})

# Finding. Notice that all values get stored as strings, hence the typecasting
Car.where(["data -> 'doors' = ?", "2"])

# Updating / Inserting
car.data['make'] = "Toyota"
car.save