sql - Using Where on association's attributes condition -


i have user model has languages attribute array (postgres)

a user has_many :documents , document belongs_to :user

i want find document written users knows english , french

@langs = ["english", "french"]  document.joins(:user).where(user.languages & @langs != nil ) 

this doesn't work.

what correct way this?

schema languages

t.string   "languages",              default: [],                                 array: true 

try this:

document.joins(:user).where("user.languages @> array[?]::varchar[]", @langs) 

this should work tried on models similar structure.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -