Pregunta

It possible to create a query for columns type => object on doctrine 2?

Domain question in:

  • Query Builder
  • DQL

Example

/**
 *
 * Capacity Object Details
 * wgross = weight of item, wnet = neto weight
 * 
 * @ORM\Column(type="object")
 */
private $capacity;

When:

$capacity = array('wgross' => 19, 'wnet' => 9);

Possible query with pseudo where:

$em->createQuery('SELECT i FROM Entity\Item i WHERE i.capacity.wnet < 18');

Doctrine serialize the object type, i search on the web for possible solutions with:

  • Doctrine Query Builder Expr
  • Regular Expression

The type of columns on RDMS is longtext and not clob or blob, with value something like this.

O:8:"stdClass":5:{s:4:"wgross";s:0:"19";s:6:"wnet";s:0:"9";}

But nothing found.

¿Fue útil?

Solución

Found a possible solution but not the optimal one is to use a like expr:

 $qb->add($qb->expr()->like("i.capacity", $qb->expr()->literal("%text_to_search%")));

And after work in memory with Doctrine Criteria.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top