如何在学说中通过qb连接?

时间:2017-02-09 06:39:32

标签: doctrine

我想在条件中添加一个连接到我的查询,但它返回了一个错误。 我们如何在学说中做到这一点? 有没有像:   $ qb-> andWhere(' p。$ gender =:g') - > setParameter(' g',$ gender);  加入学说symfony ??

   $qb->select("p")->from("PfmSanadBundle:Person",  "p");

    if ((isset($province) && trim($province) !== '') && (isset($City) && trim($City) !== '')){
        $qb->join("p" ,"students", "ps")
            ->join("ps" ,"organization", "po")
            ->join("po" ,"cityProvince", "pc")
            ->join("pc" ,"province", "pp");
    }
   if ((isset($province) && trim($province) !== '') && !isset($City)) {
        $qb->join("p.students", "ps")
            ->join("ps.organization", "po");
    }
    $res = $qb->getQuery()->getArrayResult();

错误(邮递员):

  

"错误":{       "代码":500,       "消息":"内部服务器错误",       "例外":[         {           "消息":" [语义错误]第0行,第49列附近的学生INNER':错误:课程' p'没有定义。",           " class":" Doctrine \ ORM \ Query \ QueryException",           "追踪":[             {

1 个答案:

答案 0 :(得分:0)

加入方法用法如下

// Example - $qb->join('u.Group', 'g', Expr\Join::WITH, $qb->expr()->eq('u.status_id', '?1'))
// Example - $qb->join('u.Group', 'g', 'WITH', 'u.status = ?1')
// Example - $qb->join('u.Group', 'g', 'WITH', 'u.status = ?1', 'g.id')
public function join($join, $alias, $conditionType = null, $condition = null, $indexBy = null);

如下行

$qb->join("p" ,"students", "ps")
    ->join("ps" ,"organization", "po")
    ->join("po" ,"cityProvince", "pc")
    ->join("pc" ,"province", "pp");

更改为

$qb->join("p.students", "ps")
    ->join("ps.organization", "po")
    ->join("po.cityProvince", "pc")
    ->join("pc.province", "pp");