我有一个模型:Unit和StringValue(继承自AbstractValue)。单位只知道AbstractValue(OneToMany)。我创建一个StringValue并将其添加到Unit。如何在dql或queryBuilder中访问StringValue.value属性?
Models:
/**
* @Entity
* @Table(name="Unit")
*/
class Unit {
...
/**
* Values
* @var Doctrine\Common\Collections\ArrayCollection
*
* @OneToMany(targetEntity="AbstractValue"
* , mappedBy="unit"
* , cascade={"persist"})
*/
private $values;
}
/**
* @Entity
* @Table(name="AbstractValue")
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({
"field" = "AbstractValue"
* , "string" = "StringValue"
* , "integer" = "IntegerValue"
* , "float" = "FloatValue"
* })
*/
abstract class AbstractValue {
...
}
/**
* @Entity
* @Table(name="StringValue")
*/
class StringValue extends AbstractValue {
/**
* String value.
* @var string
*
* @Column(name="value", type="string", length="255")
*/
private $value;
}
//make a unit with value:
$Unit = new Unit;
$Value = new StringValue;
$Unit->addValue($value);
//persist/flush
//make a query select
$queryBuilder = $em->createQueryBuilder();
$queryBuilder
->select('u')
->from('Unit', 'u')
->leftJoin('u.values', 'v');
$queryBuilder
->andWhere('v.value = :brand')
->setParameter('brand', 'qweqwee');
//error:
Exception [Doctrine\ORM\Query\QueryException] information:
Message: [Semantical Error] line 0, col 130 near 'value = :bra': Error: Class AbstractValue has no field or association named value