Reputation: 24905
This is a follow up question to this one:
How to select only part of json, stored in Postgres, with ActiveRecord
Say I have a model User
, which has a field of type json
called settings
. Let's assume that this field looks roughly like this:
{
color: 'red',
language: 'English',
subitems:
{
item1: true,
item2: 43,
item3: ['foo', 'bar', 'baz']
}
}
The difference to the question cited above is that I'd like to know how to exclude part of the json. So here, I want to select everything from settings
except:
subitems:
{
item1: true,
item2: 43,
item3: ['foo', 'bar', 'baz']
}
Upvotes: 1
Views: 678
Reputation: 286
in my case,
>>User.select("subitem -> 'item1' AS subitem1", "subitem->'item2' AS subitem2").map(&:attributes)
with rails 5
Upvotes: 2