Anthony
Anthony

Reputation: 87

Symfony + doctrine : select clause where don't work

Clause where not working on a simple array type. The condition is cc.isActive = :active

return $qb->select('c')
        ->from('Win4uAdminBundle:ColorGammeCor', 'c')
        ->innerJoin('Win4uAdminBundle:Color', 'cc')
        ->where('c.type = :type')
        ->andWhere('cc.isActive = :active ')
        ->andWhere('c.gamme = :gamme_id')
        ->addGroupBy('c.colorExt')
        ->setParameter('type', $type)
        ->setParameter('active', 1)
        ->setParameter('gamme_id', $gammeId)
        ->getQuery()->getResult();

Here the filed definition :

/**
 * @ORM\Column(name="is_active", type="simple_array", columnDefinition="TINYINT(1) NULL")
 */
private $isActive;

If the content of the field is_active is null, this query return the records... why? I ask only is_active = 1

Many thanks

Upvotes: 0

Views: 484

Answers (1)

dchesterton
dchesterton

Reputation: 2110

You can always debug the actual SQL Doctrine is calling by executing $qb->getQuery()->getSQL() where $qb is your QueryBuilder object, or by looking at the Symfony toolbar.

There's two issues with the code. Firstly, the definition of the $isActive field is wrong, it should be a boolean rather than a simple_array:

/**
 * @ORM\Column(name="is_active", type="boolean")
 */
private $isActive;

Secondly, the innerJoin should specify the relation on Win4uAdminBundle:ColorGammeCor, so it should be something similar to:

return $qb->select('c')
    ->from('Win4uAdminBundle:ColorGammeCor', 'c')
    ->innerJoin('c.color', 'cc')

Upvotes: 1

Related Questions