2014-03-25 15:55
浏览 42

Symfony2 + Doctrine + Repository:这个函数不应该返回对象而不是数组

I have this function in my repository:

public function findLatestFeeAsigned($company_id) {
    $qb = $this->getEntityManager()->createQueryBuilder();

    $qb->select('c', 'chw');
    $qb->from('Configuration\FeeBundle\Entity\Fee', 'c');
    $qb->leftJoin('Company\ApprovalBundle\Entity\CompanyHasWtax', 'chw', \Doctrine\ORM\Query\Expr\Join::WITH, ' = chw.wtax');
    $qb->where(' = ?1');
    $qb->orderBy('chw.created', 'ASC');
    $qb->setParameter(1, $company_id);

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

And I call it from my controller in this way:

$entityCurrentFee = $em->getRepository('ApprovalBundle:CompanyHasWtax')->findLatestFeeAsigned($id);

Where $id is a request parameter. Then I try to get the some column values as:


But I got error saying that $entityCurrentFee is not a object, why is that?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongyanju0945 2014-03-25 15:58

    If you're querying by the primary key or just expecting to retrieve single object, you should use


    Beware that this function throws NoResultException

    打赏 评论

相关推荐 更多相似问题