I want to join
comments regardless if comments exist or not.
You can use
includes for that:
But that results in 2 queries, one to get all the posts, and one to get all comments that have the relevant post_id.
references you can turn this into an outer join:
Now we’re getting all the information we need with just 1 query.
Check out the Active Record guides hereTweet