I have two tables, posts and images. Here is the relevant section from schema.rb:
create_table "posts", force: true do |t|
t.string "name"
t.string "body"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "images", force: true do |t|
t.integer "post_id"
t.string "service_name"
t.string "service_url"
t.datetime "created_at"
t.datetime "updated_at"
end
I want to find all the posts and join it with the images table, with a where clause on the images. I still want all of the posts to return, even if they don't have images that match the where clause.
I still expect this query to return all the posts, even if there are no images with a service name of "acme":
Post.includes(:images).where("images.service_name" => "acme")
According to the rails guide on querying,
If, in the case of this includes query, there were no comments for any posts, all the posts would still be loaded. By using joins (an INNER JOIN), the join conditions must match, otherwise no records will be returned.
but that's not the behavior I'm seeing. In the case of no images, I'm getting no results pack from my query.
I appreciate any ideas.