Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails 3 postgres array support

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.

like image 580
yee379 Avatar asked Nov 23 '25 01:11

yee379


1 Answers

In case someone finds this and like me is looking to add support to a Rails 3.2 app I found the 1.0 version of postgres_ext gem.

The 1.0 version has a dependency on ActiveRecord 3.2.

Higher major versions are for use with Rails 4.

like image 106
PaddyDwyer Avatar answered Nov 24 '25 22:11

PaddyDwyer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!