简体   繁体   English

Symfony学说QueryBuilder

[英]Symfony Doctrine QueryBuilder

I try to convert this query to the querybuilder: 我尝试将此查询转换为querybuilder:

SELECT *, landingpages_content.id as cid FROM `landingpages_content` LEFT JOIN content ON landingpages_content.content_id = content.id WHERE content.enabled = 1 AND landingpages_content.landingpage_id = ? ORDER BY landingpages_content.`order`

This is my QueryBuilder code: 这是我的QueryBuilder代码:

$queryBuilder
    ->select('*, landingpages_content.id as cid')
    ->from('landingpages_content', 'landingpages_content')
    ->leftJoin('landingpages_content.content_id', 'content.id', null)
    ->where('content.enabled = 1')
    ->andWhere('landingpages_content.landingpage_id = :id')
    ->setParameter('id', $id)
    ->orderBy('landingpages_content.`order`', 'ASC');

It returns 它返回

InvalidArgumentException: The query builder cannot have joins. InvalidArgumentException:查询构建器不能具有联接。

You are using leftJoin method wrong. 您正在使用leftJoin方法错误。 Try something like this: 尝试这样的事情:

$queryBuilder
    ->select('*, landingpages_content.id as cid')
    ->from('landingpages_content', 'landingpages_content')
    ->leftJoin('landingpages_content.content', 'content', 'ON', 'landingpages_content.content_id = content.id')
    ->where('content.enabled = 1')
    ->andWhere('landingpages_content.landingpage_id = :id')
    ->setParameter('id', $id)
    ->orderBy('landingpages_content.order', 'ASC');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM