This project is archived and is in readonly mode.
.count on query with a .joins and a nested .includes fails
-
Neeraj Singh
- Importance changed from to Low
A url has many pages or a url has one page? Could you specify that relationship?
-
Fluxx
Url has_one :page. Sorry about forgetting to add that. I've updated the original ticket text to reflect it as well.
-
Neeraj Singh
If you don't mind can you paste migrations so that I don't need to type them. Sorry just being lazy :-)
-
Fluxx
Here are the migrations, edited for simplicity. I haven't actually tried to run this specific code yet, so if it doesn't work let me know.
create_table "issues", :force => true do |t| t.string "name", :limit => 100 end create_table "issuances", :force => true do |t| t.integer "crawl_id", :null => false t.integer "issue_id", :null => false t.integer "url_id", :null => false end create_table "pages", :force => true do |t| t.string "title" t.integer "url_id", :null => false end create_table "urls", :force => true do |t| t.string "url", :null => false end -
Neeraj Singh
works fine for me. I used rails edge.
ree-1.8.7-2010.02 > Issuance.joins(:issue).includes(:url).count SQL (0.3ms) SELECT name FROM sqlite_master WHERE type = 'table' AND NOT name = 'sqlite_sequence' SQL (0.2ms) SELECT COUNT(DISTINCT "issuances"."id") FROM "issuances" INNER JOIN "issues" ON "issues"."id" = "issuances"."issue_id" LEFT OUTER JOIN "urls" ON "urls"."id" = "issuances"."url_id" => 0 ree-1.8.7-2010.02 > Issuance.joins(:issue).includes(:url => :page).count SQL (0.4ms) SELECT COUNT(DISTINCT "issuances"."id") FROM "issuances" INNER JOIN "issues" ON "issues"."id" = "issuances"."issue_id" LEFT OUTER JOIN "urls" ON "urls"."id" = "issuances"."url_id" LEFT OUTER JOIN "pages" ON "pages"."url_id" = "urls"."id" => 0 ree-1.8.7-2010.02 > Issuance.includes(:url => :page).count SQL (0.4ms) SELECT COUNT(DISTINCT "issuances"."id") FROM "issuances" LEFT OUTER JOIN "urls" ON "urls"."id" = "issuances"."url_id" LEFT OUTER JOIN "pages" ON "pages"."url_id" = "urls"."id" => 0 -
Neeraj Singh
- State changed from new to resolved
-
Fluxx
Just verified the fix for the previous bug running HEAD for 3-0-stable. Thanks guys.