简体   繁体   中英

Doctrine 2 ORM problem setting parameters

I'm having a problem with a very simple query in Doctrine 2 ORM. I'm sure I've followed the docs to the letter, but it just won't work. I have this:

$qb = $this->em->createQueryBuilder()
    ->select('p')
    ->from('Property', 'p')
    ->where('type = :type');
$properties = $qb->getQuery()->setParameters(array(
    'type' => 'house',
))->getResult();

And I get:

QueryException: [Semantical Error] line 0, col 46 near 'type = :type': Error: 'type' is not defined.

I've also tried:

$properties = $qb->getQuery()->setParameters(array(
    ':type' => 'house',
))->getResult();

With no luck. I'm sure this must be so simple, but I just can't see what's wrong.
Thanks.

->where('p.type = :type');

在这种情况下,您始终必须指定属性的所有者- Property实体。

I've always done setParameter() on the QueryBuilder, not on the query.

Try

$qb = $this->em->createQueryBuilder()
    ->select('p')
    ->from('Property', 'p')
    ->where('type = :type');

$qb->setParameters(array('type' => 'house'));

$properties = $qb->getQuery()->getResult();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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