php - Assign and update entity property in Symfony2 form -
is there anyway can assign entity , edit 1 of it's properties in single symfony2 form?
example:
tasks have many activities.
when create activity assign task through entity form field. want update task remainingestimateinseconds when entity created.
activity entity:
<?php namespace appbundle\entity; /** * activity * * @orm\table() * @orm\entity(repositoryclass="appbundle\entity\activityrepository") */ class activity { /** * @orm\column(name="id", type="integer") * @orm\id * @orm\generatedvalue(strategy="auto") */ private $id; /** * @assert\notnull() * @orm\manytoone(targetentity="task") */ private $task; }
task entity:
<?php namespace appbundle\entity; use doctrine\orm\mapping orm; /** * task * * @orm\table() * @orm\entity(repositoryclass="appbundle\entity\taskrepository") */ class task { /** * @var integer * * @orm\column(name="id", type="integer") * @orm\id * @orm\generatedvalue(strategy="auto") */ private $id; /** * @assert\notblank() * @orm\column(name="title", type="string", length=255) */ private $title; /** * @orm\column(name="remainingestimateinseconds", type="integer", length=255, nullable=true) */ private $remainingestimateinseconds; }
activity form:
my current implementation using non-mapped field. remaining estimate set onto task in controller isn't best implementation.
<?php namespace appbundle\form; use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface; use symfony\component\optionsresolver\optionsresolver; use symfony\component\validator\constraints\notnull; class activitytype extends abstracttype { /** * @param formbuilderinterface $builder * @param array $options */ public function buildform(formbuilderinterface $builder, array $options) { $builder->add('description'); $builder->add('task'); $builder->add('remainingestimateinseconds', 'integer', array( 'mapped' => false, 'constraints' => array( new notnull() ) )); } /** * @param optionsresolver $resolver */ public function configureoptions(optionsresolver $resolver) { $resolver->setdefaults( array( 'data_class' => 'appbundle\entity\activity', ) ); } /** * @return string */ public function getname() { return 'activity'; } }
i tried using property_path => "task.remainingestimateinseconds"
duplicate property_path
throwing kind of error.
what using non-mapped field post_set_data , post_submit listeners on main form prepopulate field/update object?
Comments
Post a Comment