【问题标题】:Symfony: How to join tables?Symfony:如何连接表?
【发布时间】:2012-01-07 08:01:10
【问题描述】:

我正在处理退出项目。我想在 SQL 查询中加入两个表。

$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();

但我收到以下错误:

您的查询中别名为“pa”的“PageAnchor”未引用 与之相关的父组件。,referer:example.com/abc/abc

有什么想法吗?

【问题讨论】:

标签: php sql join symfony1 doctrine


【解决方案1】:

试试这个:

$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();

参考:

http://www.doctrine-project.org/documentation/manual/1_2/ru/dql-doctrine-query-language:join-syntax

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 2017-05-20
    • 2016-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-12
    相关资源
    最近更新 更多