I was out of order. *Implicit* joins have no order, but this
SQL actually is invalid. The explicit join syntax takes the
previous result and joins it on specified fields to one new
table, which is symmetric but must join the left side to the
right side of the join. It doesn't in this case.

Clifford Heath.

On 26/09/2009, at 7:16 AM, Tony Mann wrote:

> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to