have a Doctrine Entity Product with a nullable relationship to Supplier.
The FieldSets are nested. If I leave the field for Supplier empty the
Doctrine Hydrator returns: A new entity was found through the relationship.
Product:
/** * @var \Entities\Supplier * *
@ORM\ManyToOne(targetEntity="Entities\Supplier") * @ORM\JoinColumns({ *
@ORM\JoinColumn(name="supplier_id", referencedColumnName="id", nullable=true) *
}) */ private $supplier;
FieldSet:
/** * Constructor for Cms\Form\SupplierFieldSet. * * @param ObjectManager
$objectManager */ public function __construct(ObjectManager $objectManager) {
parent::__construct('supplier'); $this->setObjectManager($objectManager);
$this->setHydrator(new
DoctrineEntity($this->getObjectManager()))->setObject(new Supplier());
$this->addElements(); }
View:
<?php $form->setAttribute('action', $this->url('product', array('action' =>
'add'))); $form->setAttribute('class', 'form-horizontal'); $form->prepare();
echo $this->form()->openTag($form); $product = $form->get('product'); $supplier
= $product->get('supplier'); ?> <div class="form-group <?=
($this->formElementErrors($supplier->get('name'))) ? 'has-error' : ''; ?>">
<?php echo $this->formHidden($supplier->get('id')); ?> <?php echo
$this->formRow($supplier->get('name')) . PHP_EOL; ?> </div>
I don't want the Hydrator to try and persist a Supplier if no value has
been given. The database doesn't require for the related entity to be
available.
I already tried removing $this->setObjectManager($objectManager);
$this->setHydrator(new
DoctrineEntity($this->getObjectManager()))->setObject(new Supplier());
I tried to implement a Null filter to set values to Null in case of empty
string.
What can be done?
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.