bob
bob

Reputation: 625

Doctrine can't find column (Error: [column] is not defined.)

I do have the following source:

//$enity = 'Company:CompanyResourceModel';
public function getAll($entity, $filter = null){
    $qb = App::DB()->createQueryBuilder();
    $data = $qb ->select('r')
        ->from($entity, 'r')
        ->where($this->getExpression($qb, $qb->expr()->andX(), $filter))
        ->getQuery()
        ->getArrayResult();

    if ( is_array($data) && !empty($data) ) {
        return $data;
    }
    return [];
}

where App::DB() contains my EntityManager and getExpression() is from here https://github.com/tarlepp/symfony-flex-backend/blob/c979e816ed5c4d02de2e857885a4b47f7e42d71e/src/Rest/RepositoryHelper.php#L152-L232

how ever, i am keep getting the folling error

Type: Doctrine\ORM\Query\QueryException
Message: [Semantical Error] line 0, col 51 near 'week = ?1': Error: 'week' is not defined.

'week' is an existing column of my table, which is defined in the given enity as

/**
 * @ORM\Column(type="integer")
 */
protected $week;

can anybody tell me where i'm going wrong or at least point me in the right direction? thanks in advance!

Upvotes: 1

Views: 1218

Answers (1)

M Khalid Junaid
M Khalid Junaid

Reputation: 64486

As per comments,

You need to refer entity property with entity alias r like

->where('r.'.$this->getExpression($qb, $qb->expr()->andX(), $filter))

Upvotes: 1

Related Questions