Reputation: 18560
I am working on exiting project. I want to join two tables in SQL query.
$this->chapterPages = Doctrine_Query::create()
->from( 'Page' )
->leftJoin('PageAnchor pa ON pa.page_id = Page.sortorder')
->where( 'Page.chapter_id = ?', $this->chapterId )
->execute();
$this->chapterPages = $this->chapterPages->toArray();
But I am getting following error:
"PageAnchor" with an alias of "pa" in your query does not reference the parent component it is related to., referer: example.com/abc/abc
Any idea ?
Upvotes: 0
Views: 1924
Reputation: 11202
Try this:
$this->chapterPages = Doctrine_Query::create()
->from( 'Page p' )
->leftJoin('p.PageAnchor pa ON pa.page_id = Page.sortorder')
->where( 'Page.chapter_id = ?', $this->chapterId )
->execute();
Reference:
http://www.doctrine-project.org/documentation/manual/1_2/ru/dql-doctrine-query-language:join-syntax
Upvotes: 1