2016-09-30 2 views
0

Wenn ich Felder meiner Entität in Symfony-Formularen hinzufüge, werden die Entitätsanmerkungen zugeordnet und basieren auf dieser Symfony-Schätzung, ob mein Feld nullfähig sein kann oder nicht, so weit so gut, wie dieser dump:Symfony forms, rate required Attribut in Assoziationsfeldern

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 

Aber wenn ich Assoziieren Felder (Fremdschlüssel) haben, hat Symfony eine andere Struktur-Mapping und erraten nicht, wenn das Feld NULL-Werte zulässt oder nicht, wie dieses Loch sein kann:

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 

In diesen Fällen muss das erforderliche Attribut m konfiguriert werden sonst, sonst wird es wahr (ist der Standardwert von Symfony Formen).

Wer weiß, wie Symfony in diesen Fällen das erforderliche Attribut erraten kann? Mein Unternehmen haben folgende Anmerkungen:

/** 
* @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; 

Antwort

0

Sie können eine TypeGuesser service erstellen. Das ist verdammt viel Arbeit, also warum nicht manuell die Felder einmal setzen und damit fertig sein?

+0

Danke für deine Antwort, für jetzt mache ich das, aber es wäre gut, wenn Symfony dies genauso machen würde wie mit den restlichen Feldern. –

Verwandte Themen