is nested json structure supported for activerecord - postgresql?

50 views
Skip to first unread message

Jae Lee

unread,
Feb 7, 2014, 7:38:14 AM2/7/14
to rubyonra...@googlegroups.com
Hi all,

I'm using rails 4.1.0.beta 1 and postgresql 9.3.1 and its native support for json column. so no special serializer or no special storage thing with active record, just plain :json type in active record migration.

in my active record model, I've got two json fields.

input: {"first_name"=>"firstName", "last_name"=>"lastName", "postcode"=>"postcode"}
output: {"customer_detail"=>{"first_name"=>"firstName", "last_name"=>"lastName", "postcode"=>"postcode"}}

model.input
=> {"first_name"=>"firstName", "last_name"=>"lastName", "postcode"=>"postcode"}

model[:input]
=> {"first_name"=>"firstName", "last_name"=>"lastName", "postcode"=>"postcode"}

model.input_before_type_cast
=> "{\"first_name\":\"firstName\", \"last_name\":\"lastName\", \"postcode\":\"postcode\"}"

model.output 
=> nil

model[:output]
=> {"customer_detail"=>{"first_name"=>"firstName", "last_name"=>"lastName", "postcode"=>"postcode"}}

model.output_before_type_cast
=> "{\"customer_detail\":{\"first_name\":\"firstName\",\"last_name\":\"lastName\",\"postcode\":\"postcode\"}}"

could someone explain why this is happening? I'm confused why this is happening...

thanks!
J

Jae Lee

unread,
Feb 7, 2014, 8:45:23 AM2/7/14
to rubyonra...@googlegroups.com
ah don't worry I've realised it was my own error...

J
Reply all
Reply to author
Forward
0 new messages