So I am attempting to do a SQL query where I need to provide a lot of user id's.
Currently what I am trying to do is this:
following_ids = $redis.smembers(self.redis_key(:following))
Medium.includes([{comments: :user}, :likes, :user]).where("user_id IN (#{ following_ids.each { |id| id } }) OR user_id = :user_id", user_id: id)
Now the following_ids is in this form: ["1", "2", "3"], containing user id's
But the loop I try to do seems to still put the whole array into the SQL statement. I can see this from my server log:
Medium Load (0.3ms) SELECT "media".* FROM "media" WHERE (user_id IN (["2", "3"]) OR user_id = 1)
PG::SyntaxError: ERROR: syntax error at or near "["
LINE 1: SELECT "media".* FROM "media" WHERE (user_id IN (["2", "3"])...
What am I doing wrong here?
("1", "2", "3")?