-1
Good afternoon, I just started working with Rails and I’m having trouble with a query. I’m building an Api where I have the Game model and the User model. A user has several games, and one game has two users (there being an intermediate Gameusers table). When using the Rails console, I can easily see the users of a game making:
83 and 84 are the ids of users belonging to that game. But if I do
I can’t do a query to return the games to which two users belong. Can anyone help me with this? Thanks
Updating
After a while I found out it would be Game.joins(:users).where(users: { id: [83 && 84] })
Thank you for your reply helped me, but in that querry are the user games 83 OR 84. The answer would be
Game.joins(:users).where(users: { id: [83 && 84] })
.– joaocostelo
Your query is not doing what you think it is doing, it executes this query you commented on and the one I mentioned in the reply and see the difference in the generated SQL query. In your case, you are only using ID 83 in the query, because [83 && 84] results in [83]. Anyway, I don’t quite understand your intention, but I’m glad the answer helped you.
– Sidney