Reputation: 75
how to make a query in a field of JSON type to return only one key? For example I have this model ActivityPart
below and I want to return the activity_json
field just a key named "image"
.
ActivityPart < ApplicationRecord {
:id => :integer,
:activity_type => :string,
:activity_json => :json,
:created_at => :datetime,
:updated_at => :datetime,
Upvotes: 0
Views: 68
Reputation: 1797
You can use following code:
activity_parties = ActivityPart.select("activity_json->'image' AS image")
And you will be able to access this column for each record
activity_parties.each { |party| party.image }
Upvotes: 1