2016-09-30 2 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は異なるマッピング構造を有し、フィールドがNULL可能であるか、またはできない場合など、このダンプと、推測していません:

など、このダンプなど
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 

このような場合、必要な属性は次のように構成する必要があります。mそれ以外の場合は真です(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が他のフィールドと同じようにこの作業を行うと良いでしょう。 –

関連する問題