I have 2 objects, visitors and events. Visitors have several events. An event stores parameters like this ...
#<Event id: 5466, event_type: "Visit", visitor_token: "c26a6098-64bb-4652-9aa0-e41c214f42cb", contact_id: 657, data: {"url"=>"http://widget.powerpress.co/", "title"=>"Home (light) | Widget"}, created_at: "2015-12-17 14:51:53", updated_at: "2015-12-17 14:51:53", website_id: 2>
As you can see, there is a serialized text column called data that stores a hash with lots of data.
I need to find out if the visitor visited a certain page, which would be very simple if the url parameter was its own column or the hash was an hstore column, however it was not initially configured this way and it is part of the saved hash.
Here are my requested rails ...
visitor.events.where("data -> url = :value", value: 'http://widget.powerpress.co/')
visitor.events.where("data like ?", "{'url' => 'http://widget.powerpress.co/'}")
visitor.events.where("data -> :key LIKE :value", :key => 'url', :value => "%http://widget.powerpress.co/%")
How to correctly request postgres to search for objects with a hash containing a key with a specific value?