2016-09-30 99 views
0

当我加入我的Symfony的形式实体领域,实体注释映射,并在此基础上的Symfony想,如果我的字段可以为空的或没有,到目前为止好,像这样的转储:Symfony的形式,猜测联想需要的属性域

public 'fieldMappings' => 
array (size=5) 
    'acl' => 
    array (size=9) 
     'fieldName' => string 'acl' (length=3) 
     'type' => string 'smallint' (length=8) 
     'scale' => int 0 
     'length' => null 
     'unique' => boolean false 
     'nullable' => boolean true 
     'precision' => int 0 
     'options' => 
     array (size=2) 
      ... 
     'columnName' => string 'acl' (length=3) 
    'id' => 
    array (size=10) 
     'fieldName' => string 'id' (length=2) 
     'type' => string 'integer' (length=7) 
     'scale' => int 0 
     'length' => null 
     'unique' => boolean true 
     'nullable' => boolean false 
     'precision' => int 0 
     'options' => 
     array (size=2) 
      ... 
     'columnName' => string 'id' (length=2) 
     'id' => boolean true 

但是,如果我有关联字段(外键),Symfony的具有不同的映射结构,不会想,如果本场可为空的或没有,像这样的转储:

public 'associationMappings' => 
array (size=3) 
    'userObj' => 
    array (size=19) 
     'fieldName' => string 'userObj' (length=7) 
     'joinColumns' => 
     array (size=1) 
      ... 
     'cascade' => 
     array (size=0) 
      ... 
     'inversedBy' => null 
     'targetEntity' => string 'AdminBundle\Entity\User' (length=23) 
     'fetch' => int 2 
     'type' => int 2 
     'mappedBy' => null 
     'isOwningSide' => boolean true 
     'sourceEntity' => string 'AdminBundle\Entity\UserAcl' (length=26) 
     '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 
    'storeObj' => 
    array (size=19) 
     'fieldName' => string 'storeObj' (length=8) 
     'joinColumns' => 
     array (size=1) 
      ... 
     'cascade' => 
     array (size=0) 
      ... 
     'inversedBy' => null 
     'targetEntity' => string 'AdminBundle\Entity\Store' (length=24) 
     'fetch' => int 2 
     'type' => int 2 
     'mappedBy' => null 
     'isOwningSide' => boolean true 
     'sourceEntity' => string 'AdminBundle\Entity\UserAcl' (length=26) 
     '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 

所以在这些情况下,所需要的属性需要配置米否则它将是真实的(是Symfony表单的默认值)。

任何人都知道的Symfony如何猜测在这些情况下所需要的属性? 我的实体有以下注释:

/** 
* @ORM\ManyToOne(targetEntity="User") 
* @ORM\JoinColumn(name="fk_user", referencedColumnName="id", nullable=false, unique=false, onDelete="CASCADE") 
*/ 
private $userObj; 

/** 
* @ORM\ManyToOne(targetEntity="Store") 
* @ORM\JoinColumn(name="fk_store", referencedColumnName="id", nullable=false, unique=false, onDelete="CASCADE") 
*/ 
private $storeObj; 

回答

0

您可以创建一个TypeGuesser service。尽管如此,这还是很多工作的一部分,那么为什么不手动设置一次字段并完成它呢?

+0

谢谢您的回答,现在我这样做,但它是很好的,如果Symfony的做好这项工作以同样的方式,因为它与其他字段一样。 –