| So the problem is active record is no good at joins? (That is, it's hard/impossible via the active record DSL to make the correct nested join?) By the way (you may know this) when staying within active record convention, you should never need to single out the ".id" and ".foreign_model_id" fields: User.joins(:comments, :likes).where(user: some_user) (where some_user is an instance of User). I'm still not quite comfortable enough with AR, but I think, leaning on this:
https://www.learneroo.com/modules/137/nodes/768 I think what you want in your second case is simply?: User.joins(:comments, :likes).where(user: some_user).uniq (I'd have to create some models and watch what ".to_sql" creates to be certain, though) |
You encounter this problem whether you use an ORM or not.