Doctrine 2 - single table inheritance - access property of child entity

Viewed 1176

I have simple table inheritance on my entities, say something like:

/** 
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="type", type="string")
* @DiscriminatorMap({"base"="BaseArticle", "extended"="ExtendedArticle"}) 
*/         
class BaseArticle extends \Models\BaseModel{
   ...
}
class ExtendedArticle extends BaseArticle{
    /**
    * @column(type="string")
    */
    protected $extendedProperty;
} 

I need to do a query across all article types, but in some types restrict the query by some property, that is in extended ExtendedArticle, ie:

SELECT a FROM BaseArticle a WHERE (a INSTANCE OF BaseAricle) OR (a INSTANCE OF ExtendedArticle AND a.extendedProperty = "xy")

Which gives me following exception:

[Semantical Error] line 0, col 406 near 'extendedProperty="xy"))': Error: Class Models\Articles\BaseArticle has no field or association named location

So question is, how to access child's properties in query to parent class?

2 Answers
Related