在symfony查询中设置参数

时间:2017-08-30 15:27:19

标签: php sql symfony

我在Symfony请求中遇到了参数问题。我有3个实体: 商场有很多商店有很多营业额

在我的营业额中,我需要从一家公司获得营业额。我这样做了:

public function findForCompany($companyId)
{   
   $qb = $this->createQueryBuilder('t')
        ->innerJoin('t.store', 's')
        ->innerJoin('s.mall', 'm')
        ->where('m.id = :companyId');

    $qb->setParameter('companyId', $companyId);

    dump($companyId);
    dump($qb->getQuery()->getSql());
    dump($qb->getQuery()->getResult());
    exit();

    return $qb->getQuery()->getResult();

}

当我转储sql时,我得到了

SELECT t0_.id AS id_0, t0_.amount AS amount_1, t0_.created_at AS created_at_2, t0_.month AS month_3, t0_.year AS year_4, t0_.is_consolidated AS is_consolidated_5, t0_.created_by AS created_by_6, t0_.store_id AS store_id_7, t0_.company_id AS company_id_8 FROM turnover t0_ INNER JOIN store s1_ ON t0_.store_id = s1_.id INNER JOIN mall m2_ ON s1_.mall_id = m2_.id WHERE m2_.id = ?

注意"?"在查询结束时。 我的查询没有结果。我错过了什么吗?

编辑:

感谢Kuba,答案只是实体关系中的错误。查询应该是:

$qb = $this->createQueryBuilder('t')
        ->innerJoin('t.store', 's')
        ->innerJoin('s.mall', 'm')
        ->where('m.company = :companyId');

0 个答案:

没有答案