我在Symfony 2应用程序中使用Doctrine。 我有抽象类Object,它是我的应用程序中的所有对象的父实体(任务,交易等)。
* @ORM\Table(name="adm_object")
* @ORM\Entity(repositoryClass="Cloud\AdmBundle\Entity\Repository\ObjectRepository")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
*/
abstract class Object extends BaseEntity
{
现在例如任务实体声明:
*
* @ORM\Table(name="crm_tasks")
* @ORM\Entity
*/
class Task extends Object
{
现在我想在应用程序中使用此函数创建自己的过滤器约束:
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
问题在于,当我尝试通过使用$ targetEntity-> getName()来获取实体类型时,它会给我'对象',而不是'任务'......是否有可能找出哪个'对象'它是吗?因为我的应用程序中有10个对象所以我需要知道我现在在SQL查询中使用哪个对象来编写适当的过滤器...
$ targetEntity变量的var_dump:
object(Doctrine\ORM\Mapping\ClassMetadata)[1412]
public 'name' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
public 'namespace' => string 'Cloud\AdmBundle\Entity' (length=22)
public 'rootEntityName' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
public 'customGeneratorDefinition' => null
public 'customRepositoryClassName' => string 'Cloud\AdmBundle\Entity\Repository\ObjectRepository' (length=50)
public 'isMappedSuperclass' => boolean false
public 'parentClasses' =>
array (size=0)
empty
public 'subClasses' =>
array (size=12)
0 => string 'Cloud\AdmBundle\Entity\Circle' (length=29)
1 => string 'Cloud\AdmBundle\Entity\Address' (length=30)
2 => string 'Cloud\AdmBundle\Entity\Note' (length=27)
3 => string 'Cloud\AdmBundle\Entity\Object1' (length=30)
4 => string 'Cloud\AdmBundle\Entity\Object2' (length=30)
5 => string 'Cloud\AdmBundle\Entity\Tag' (length=26)
6 => string 'Cloud\CalBundle\Entity\Event' (length=28)
7 => string 'Cloud\CrmBundle\Entity\Contact' (length=30)
8 => string 'Cloud\CrmBundle\Entity\Lead' (length=27)
9 => string 'Cloud\CrmBundle\Entity\ContactInformation' (length=41)
10 => string 'Cloud\CrmBundle\Entity\Deal' (length=27)
11 => string 'Cloud\CrmBundle\Entity\Task' (length=27)
public 'namedQueries' =>
array (size=0)
empty
public 'namedNativeQueries' =>
array (size=0)
empty
public 'sqlResultSetMappings' =>
array (size=0)
empty
public 'identifier' =>
array (size=1)
0 => string 'id' (length=2)
public 'inheritanceType' => int 2
public 'generatorType' => int 4
public 'fieldMappings' =>
array (size=4)
'id' =>
array (size=9)
'fieldName' => string 'id' (length=2)
'type' => string 'integer' (length=7)
'scale' => int 0
'length' => null
'unique' => boolean false
'nullable' => boolean false
'precision' => int 0
'columnName' => string 'id' (length=2)
'id' => boolean true
'add' =>
array (size=9)
'fieldName' => string 'add' (length=3)
'type' => string 'datetime' (length=8)
'scale' => int 0
'length' => null
'unique' => boolean false
'nullable' => boolean true
'precision' => int 0
'columnName' => string 'add' (length=3)
'quoted' => boolean true
'mod' =>
array (size=9)
'fieldName' => string 'mod' (length=3)
'type' => string 'datetime' (length=8)
'scale' => int 0
'length' => null
'unique' => boolean false
'nullable' => boolean true
'precision' => int 0
'columnName' => string 'mod' (length=3)
'quoted' => boolean true
'del' =>
array (size=9)
'fieldName' => string 'del' (length=3)
'type' => string 'datetime' (length=8)
'scale' => int 0
'length' => null
'unique' => boolean false
'nullable' => boolean true
'precision' => int 0
'columnName' => string 'del' (length=3)
'quoted' => boolean true
public 'fieldNames' =>
array (size=4)
'id' => string 'id' (length=2)
'add' => string 'add' (length=3)
'mod' => string 'mod' (length=3)
'del' => string 'del' (length=3)
public 'columnNames' =>
array (size=4)
'id' => string 'id' (length=2)
'add' => string 'add' (length=3)
'mod' => string 'mod' (length=3)
'del' => string 'del' (length=3)
public 'discriminatorValue' => string 'object' (length=6)
public 'discriminatorMap' =>
array (size=13)
'object' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'circle' => string 'Cloud\AdmBundle\Entity\Circle' (length=29)
'address' => string 'Cloud\AdmBundle\Entity\Address' (length=30)
'note' => string 'Cloud\AdmBundle\Entity\Note' (length=27)
'object1' => string 'Cloud\AdmBundle\Entity\Object1' (length=30)
'object2' => string 'Cloud\AdmBundle\Entity\Object2' (length=30)
'tag' => string 'Cloud\AdmBundle\Entity\Tag' (length=26)
'event' => string 'Cloud\CalBundle\Entity\Event' (length=28)
'contact' => string 'Cloud\CrmBundle\Entity\Contact' (length=30)
'lead' => string 'Cloud\CrmBundle\Entity\Lead' (length=27)
'contactinformation' => string 'Cloud\CrmBundle\Entity\ContactInformation' (length=41)
'deal' => string 'Cloud\CrmBundle\Entity\Deal' (length=27)
'task' => string 'Cloud\CrmBundle\Entity\Task' (length=27)
public 'discriminatorColumn' =>
array (size=5)
'name' => string 'type' (length=4)
'type' => string 'string' (length=6)
'length' => null
'columnDefinition' => null
'fieldName' => string 'type' (length=4)
public 'table' =>
array (size=2)
'name' => string 'adm_object' (length=10)
'options' =>
array (size=0)
empty
public 'lifecycleCallbacks' =>
array (size=0)
empty
public 'entityListeners' =>
array (size=1)
'postPersist' =>
array (size=1)
0 =>
array (size=2)
...
public 'associationMappings' =>
array (size=4)
'relation1' =>
array (size=15)
'fieldName' => string 'relation1' (length=9)
'mappedBy' => string 'relation1' (length=9)
'targetEntity' => string 'Cloud\AdmBundle\Entity\ObjectHasObject' (length=38)
'cascade' =>
array (size=0)
...
'orphanRemoval' => boolean false
'fetch' => int 2
'type' => int 4
'inversedBy' => null
'isOwningSide' => boolean false
'sourceEntity' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'isCascadeRemove' => boolean false
'isCascadePersist' => boolean false
'isCascadeRefresh' => boolean false
'isCascadeMerge' => boolean false
'isCascadeDetach' => boolean false
'relation2' =>
array (size=15)
'fieldName' => string 'relation2' (length=9)
'mappedBy' => string 'relation2' (length=9)
'targetEntity' => string 'Cloud\AdmBundle\Entity\ObjectHasObject' (length=38)
'cascade' =>
array (size=0)
...
'orphanRemoval' => boolean false
'fetch' => int 2
'type' => int 4
'inversedBy' => null
'isOwningSide' => boolean false
'sourceEntity' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'isCascadeRemove' => boolean false
'isCascadePersist' => boolean false
'isCascadeRefresh' => boolean false
'isCascadeMerge' => boolean false
'isCascadeDetach' => boolean false
'circle' =>
array (size=19)
'fieldName' => string 'circle' (length=6)
'joinColumns' =>
array (size=1)
...
'cascade' =>
array (size=0)
...
'inversedBy' => null
'targetEntity' => string 'Cloud\AdmBundle\Entity\Circle' (length=29)
'fetch' => int 2
'type' => int 2
'mappedBy' => null
'isOwningSide' => boolean true
'sourceEntity' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'isCascadeRemove' => boolean false
'isCascadePersist' => boolean false
'isCascadeRefresh' => boolean false
'isCascadeMerge' => boolean false
'isCascadeDetach' => boolean false
'sourceToTargetKeyColumns' =>
array (size=1)
...
'joinColumnFieldNames' =>
array (size=1)
...
'targetToSourceKeyColumns' =>
array (size=1)
...
'orphanRemoval' => boolean false
'user' =>
array (size=19)
'fieldName' => string 'user' (length=4)
'joinColumns' =>
array (size=1)
...
'cascade' =>
array (size=0)
...
'inversedBy' => null
'targetEntity' => string 'Cloud\AdmBundle\Entity\AdmUser' (length=30)
'fetch' => int 2
'type' => int 2
'mappedBy' => null
'isOwningSide' => boolean true
'sourceEntity' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'isCascadeRemove' => boolean false
'isCascadePersist' => boolean false
'isCascadeRefresh' => boolean false
'isCascadeMerge' => boolean false
'isCascadeDetach' => boolean false
'sourceToTargetKeyColumns' =>
array (size=1)
...
'joinColumnFieldNames' =>
array (size=1)
...
'targetToSourceKeyColumns' =>
array (size=1)
...
'orphanRemoval' => boolean false
public 'isIdentifierComposite' => boolean false
public 'containsForeignIdentifier' => boolean false
public 'idGenerator' =>
object(Doctrine\ORM\Id\IdentityGenerator)[1402]
private 'sequenceName' => null
public 'sequenceGeneratorDefinition' => null
public 'tableGeneratorDefinition' => null
public 'changeTrackingPolicy' => int 1
public 'isVersioned' => null
public 'versionField' => null
public 'reflClass' =>
object(ReflectionClass)[1390]
public 'name' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
public 'isReadOnly' => boolean false
protected 'namingStrategy' =>
object(Doctrine\ORM\Mapping\DefaultNamingStrategy)[381]
public 'reflFields' =>
array (size=8)
'id' =>
object(ReflectionProperty)[1401]
public 'name' => string 'id' (length=2)
public 'class' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'add' =>
object(ReflectionProperty)[1407]
public 'name' => string 'add' (length=3)
public 'class' => string 'Cloud\ApplicationBundle\Entity\BaseEntity' (length=41)
'mod' =>
object(ReflectionProperty)[1198]
public 'name' => string 'mod' (length=3)
public 'class' => string 'Cloud\ApplicationBundle\Entity\BaseEntity' (length=41)
'del' =>
object(ReflectionProperty)[1404]
public 'name' => string 'del' (length=3)
public 'class' => string 'Cloud\ApplicationBundle\Entity\BaseEntity' (length=41)
'relation1' =>
object(ReflectionProperty)[1408]
public 'name' => string 'relation1' (length=9)
public 'class' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'relation2' =>
object(ReflectionProperty)[1409]
public 'name' => string 'relation2' (length=9)
public 'class' => string 'Cloud\AdmBundle\Entity\Object' (length=29)
'circle' =>
object(ReflectionProperty)[1202]
public 'name' => string 'circle' (length=6)
public 'class' => string 'Cloud\ApplicationBundle\Entity\BaseEntity' (length=41)
'user' =>
object(ReflectionProperty)[1197]
public 'name' => string 'user' (length=4)
public 'class' => string 'Cloud\ApplicationBundle\Entity\BaseEntity' (length=41)
private '_prototype' (Doctrine\ORM\Mapping\ClassMetadataInfo) => null
public 'inheritanceMapping' =>
array (size=8)
'id' => null
'relation1' => null
'relation2' => null
'circle' => null
'user' => null
'add' => null
'mod' => null
'del' => null