I have a models: Unit and StringValue (inherited from AbstractValue). Unit only knows about AbstractValue (OneToMany). I create a StringValue and add it to Unit. How can I access StringValue.value property in dql or queryBuilder ?
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")
* @DiscriminatorM开发者_开发百科ap({
"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
精彩评论