ruby on rails - find_by() in json data -


i using ahoy gem analytics. in ahoy_events table, have properties column of json data type. want find specific data based on column.

suppose have

{"tag":"a","class":"bigyapan-6","page":"/client/dashboard","text":"","href":"http://www.google.com"} 

this data , want find_by class.

in rails c ran ahoy::event.find_by(properties[:class]: "bigyapan-6") , gave me err

ahoy::event.find_by(properties["class"]: "bigyapan-6") syntaxerror: unexpected ')', expecting end-of-input 

this syntax error since properties[:class] not valid hash key in ruby. query postgres json columns need provide query string:

ahoy::event.find_by("properties ->> 'class' = 'bigyapan-6'") 

activerecord not take nested hash in case association. doubt activerecord ever support since rbdms specific , type coercion thing (-> vs ->>) make complex.

# won't work. ahoy::event.find_by(properties: { class: 'bigyapan-6' }) 

see:


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -