This mapping worked:
@fbc = FbComments.where("reviewee_id = ?", current_user.id)
@users = User.order("last_name")
@fb_comments = @fbc.map! { |fb| [fb, @users.find_by_id(fb.user_id)] }
So two arrays are mapped… one with comments and one with the user data of the person that made the comments. But I also need the user’s profile picture data. Do i change the original mapping method to include a third array somehow (e.g. @fbc + @users + @pictures), or do i have to map another array on the result of mapping the first two (e.g. @fb_comments + @pictures)?
Profile pictures, like comments, have a user_id that is matched to the id of the user who made the comments.
Thanks.
I’m not sure why you’re doing this the way you are. Why not use a join (
.includes) to get everything in one query?(I’m assuming here that profile picture data is its own model called
Picture. Change it to fit your app if necessary.)Take a look at the documentation and scroll down to “Eager loading of associations.”