First, the quick synopsis. Datamapper is generating this query:
SELECT COUNT(*) FROM `crawled_pages`
INNER JOIN `recruiters` ON `board_accounts`.`recruiter_id` =
`recruiters`.`id`
INNER JOIN `crawling_runs` ON `crawled_pages`.`crawling_run_id` =
`crawling_runs`.`id`
INNER JOIN `board_accounts` ON `crawling_runs`.`board_account_id` =
`board_accounts`.`id`
WHERE `board_accounts`.`board_id` = 'board1'
MySQL is not happy with this, since the INNER JOINs are in the wrong order.
If I change the order of the JOINs around, the query works:
SELECT COUNT(*) FROM `crawled_pages`
INNER JOIN `crawling_runs` ON `crawled_pages`.`crawling_run_id` =
`crawling_runs`.`id`
INNER JOIN `board_accounts` ON `crawling_runs`.`board_account_id` =
`board_accounts`.`id`
INNER JOIN `recruiters` ON `board_accounts`.`recruiter_id` =
`recruiters`.`id`
WHERE `board_accounts`.`board_id` = 'board1'
This has nothing to do with dm-aggregate, as I can repro the problem using
Model.all.
Here is the code that generates the errant query:
CrawledPage.count('crawling_run.board_account.board_id' => 'board1')
And here are the models (extraneous code removed):
class CrawledPage
property :id, Serial
belongs_to :crawling_run
end
class CrawlingRun
property :id, Serial
belongs_to :board_account
has n, :crawled_pages
end
class BoardAccount
property :id, Serial
belongs_to :board
belongs_to :recruiter, :nullable => true
has n, :crawling_runs
end
class Recruiter
property :id, Serial
has n, :board_accounts
end
Anyone know if this has been fixed in 0.10.1 or filed as a ticket? If I want
to fix this, any suggestions where to dive in?
Thanks.
..tony..
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---