How to exclude json parts stored in Postgres when selecting using ActiveRecord?

This is the next question to this:

How to select only json part stored in Postgres using ActiveRecord

Say I have a User model that has a json type field called settings . Suppose this field looks something like this:

 { color: 'red', language: 'English', subitems: { item1: true, item2: 43, item3: ['foo', 'bar', 'baz'] } } 

The difference in the question mentioned above is that I would like to know how to exclude the json part. So here I want to highlight everything from settings , except:

 subitems: { item1: true, item2: 43, item3: ['foo', 'bar', 'baz'] } 
0
source share
1 answer

in my case,
>>User.select("subitem -> 'item1' AS subitem1", "subitem->'item2' AS subitem2").map(&:attributes)

with rails 5

+1
source

Source: https://habr.com/ru/post/1242699/


All Articles