ruby on rails - How do I do a where query on a SQL column against multiple values? -


this query looks like:

connection.where("invited_user_id = :user_a_id , inviter_user_id = :user_b_id", user_a_id: self.inviter.try(:id), user_b_id: self.invited.try(:id)).exists? 

what check invited_user_id against multiple options, e.g. invited_user_id = [:user1, :user2]. doesn't work.

how can check see if value in column invited_user_id in either of variables :user1, :user2 or other of multiple variables.

is possible without using explicit or approach that's less dry?

never put values directly in query, that's not safe. parameterize query using ? operator.

invited_user_ids = [:user1, :user2] connection.where("invited_user_id in (?)", invited_user_ids) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -