this first symfony project, , can't figure out how solve problem.
basically, i'm trying make invoice using form.
i have "facturation" (ie invoice) entity, "typeofservice" entity, , "service" entity (the sole attribute of quantity of type of service needed invoice) acts association class.
i'd dynamically add "new service" fields facturationtype form using javascript (probably angularjs). have create n new service entities each associate both facturation entity , existing typeofservice entity.
here's facturation entity:
use doctrine\orm\mapping orm; /** * facturation * * @orm\table(name="facturation") * @orm\entity */ class facturation { ... /** * @orm\onetomany(targetentity="service", mappedby="facturation") */ private $service; /** * add service * * @param \appbundle\entity\service $service * @return facturation */ public function addservice(\appbundle\entity\service $service) { $this->service[] = $service; return $this; } /** * remove service * * @param \appbundle\entity\service $service */ public function removeservice(\appbundle\entity\service $service) { $this->service->removeelement($service); } /** * service * * @return \doctrine\common\collections\collection */ public function getservice() { return $this->service; } }
then service:
<?php namespace appbundle\entity; use doctrine\orm\mapping orm; /** * service * * @orm\table(name="service") * @orm\entity */ class service { /** * @orm\id * @orm\column(type="integer") * @orm\generatedvalue(strategy="auto") */ private $id; /** * @orm\column(type="integer", nullable=true) */ private $quantity; /** * @orm\manytoone(targetentity="typeofservice", inversedby="service") * @orm\joincolumn(name="type_of_service_id", referencedcolumnname="id") */ private $typeofservice; /** * @orm\manytoone(targetentity="facturation", inversedby="service") * @orm\joincolumn(name="facturation_id", referencedcolumnname="id") */ private $facturation; /** * id * * @return integer */ public function getid() { return $this->id; } /** * set quantity * * @param integer $quantity * @return service */ public function setquantity($quantity) { $this->quantity = $quantity; return $this; } /** * quantity * * @return integer */ public function getquantity() { return $this->quantity; } /** * set typeofservice * * @param \appbundle\entity\typeofservice $typeofservice * @return service */ public function settypeofservice(\appbundle\entity\typeofservice $typeofservice = null) { $this->typeofservice = $typeofservice; return $this; } /** * typeofservice * * @return \appbundle\entity\typeofservice */ public function gettypeofservice() { return $this->typeofservice; } /** * set facturation * * @param \appbundle\entity\facturation $facturation * @return service */ public function setfacturation(\appbundle\entity\facturation $facturation = null) { $this->facturation = $facturation; return $this; } /** * facturation * * @return \appbundle\entity\facturation */ public function getfacturation() { return $this->facturation; } }
and typeofservice
<?php namespace appbundle\entity; use doctrine\orm\mapping orm; /** * typeofservice * * @orm\table(name="type_of_service") * @orm\entity */ class typeofservice { /** * @orm\id * @orm\column(type="integer") * @orm\generatedvalue(strategy="auto") */ private $id; /** * @orm\column(nullable=true) */ private $name; /** * @orm\column(type="integer", nullable=true) */ private $priceperunit; /** * @orm\onetomany(targetentity="service", mappedby="typeofservice") */ private $service; ... /** * constructor */ public function __construct() { $this->service = new \doctrine\common\collections\arraycollection(); } /** * add service * * @param \appbundle\entity\service $service * @return typeofservice */ public function addservice(\appbundle\entity\service $service) { $this->service[] = $service; return $this; } /** * remove service * * @param \appbundle\entity\service $service */ public function removeservice(\appbundle\entity\service $service) { $this->service->removeelement($service); } /** * service * * @return \doctrine\common\collections\collection */ public function getservice() { return $this->service; } }
can point me in right direction ?
for looking, i've cracked it.
this looking for:
http://symfony.com/doc/current/cookbook/form/form_collections.html
this allows dynamic field additions, using js. careful cascade association. in case:
class facturation { .... /** * @orm\onetomany(targetentity="service", mappedby="facturation", cascade={"persist", "remove"}) */ private $services;