sql - Get records by hash value -


i'm trying records table hash value. here record example:

activity:0x0000000709be18> {                 :id => 1,       :trackable_id => 3,     :trackable_type => "user",           :owner_id => 1,         :owner_type => "user",                :key => "user.ban",         :parameters => {         :status => "new"     },       :recipient_id => nil,     :recipient_type => nil,         :created_at => wed, 01 jun 2016 22:19:39 utc +00:00,         :updated_at => wed, 01 jun 2016 22:19:39 utc +00:00 } 

i need activities paremeters status new (parameters[:status] == 'new').

this code works, need return activerecord relation not array.

activity.select{|act| act.parameters == { status: 'new'}} 

it not easy search within serialized field, can use like limitations.

activity.where('parameters ?', '%status: new%')

this working, suggest adding custom field, public activity gem owner has mentioned:

"besides few fields every activity has, can set custom fields. beneficial, parameters serialized hash, cannot queried database."


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo