In Rails 3.2, on a User show page I’m trying to display a list of Users that user has liked or tagged.
@user = User.find(params[:id])
@users = User.where(( id: @user.tags.uniq.map(&:user_id)) | (id: @user.likes.uniq.map(&:user_id)) )
This is giving a syntax error. I’ve tried a few other permutations, but no luck.
What is the correct syntax to perform an OR query on two associations?
Thanks
As you are using the id column for both queries you can combine the ids of both
@user.tagsand@user.likesbefore doing a find.You can probably refine this even more but this looks easier to understand to me.