Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i have a query in postgres that returns back a postgres array in one of the columns:

SELECT e.context->'device' AS device, count(e.data->'model_name') AS members, ARRAY_AGG(e.data->'model_name') AS models
  FROM entity AS e
  WHERE e.data->'type'='chassis' GROUP BY e.context->'device', e.data->'model_name';

is there a gem or serialize statement i could use to map the rails 3 model so that i could use models directly as a ruby array?

i know i could loop through it in the controller, but that seems not very DRY.

share|improve this question

2 Answers 2

The closest I have been able to find is activerecord-postgres-array. It isn't clear how well maintained it is, but in general the actual code is not too complex or unstable and so I would expect it would be reasonable to work with.

I say this as someone who used to process these manually in Perl before DD::Pg got direct support for Pg arrays. The code is simple and relatively unchanging, and so the fact that there are a number of releases in the past suggests that this is where to start.

share|improve this answer
up vote 0 down vote accepted

just to close this out: in the end i upgraded to rails4. it has great support for both arrays and hashes.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.