Search code examples
ruby-on-railsruby-on-rails-3postgresqlhstore

How to store hash-like objects in a PostgreSQL database?


First, a bit of info. My Rails app has a model called Neo which in turn has attributes observed_at, ra and dec.

However, I now found that I need to store sets of this data (in Python-like fashion it would be a list of tuples.) In Ruby, that would probably be a list of lists.

How can I achieve this? I don't mind using hstore but I would prefer not to as the docs on that are few.


Solution

  • You can use the simpler serialize, instead of hstore.

    Alternatively, you can create a model for these sets, then use has_many on Neo, and belongs_to on the new model.