Answer the question
In order to leave comments, you need to log in
Displaying entities, their relationships with each other. How to access them from form classes, including embedded ones?
Situation:
1. Displaying relationships between entities - in test mode,
you can take parent entities from the controller and, through their field properties, query related (child)
entities and, accordingly, any of their field properties - everything is configured, everything works - all data is taken
from corresponding database tables.
2. Now I'm trying to map entities and display relationships between entities
to shove calls from the class (s) of forms or in other words: to tie the work of forms (form classes) to
existing related entities - this is where I have a wedge. I read up and down
the docks on forms and embedded forms (subforms as a collection) and I can’t comprehend the mechanism of this -
and the QUESTION itself:
how to indicate relationships between forms, base and
embedded in it, on top of mappings of relationships in entities. On the forums they write, use the documentation - everything is there, yes, the
documentation has about displaying links - separately, about forms - separately. In the Doctrine Dock, when
using a collection, the collection is placed on the reverse side of the entity relationship. In the Forms and Collections doc,
the collection is placed on the direct side of the relationships between forms. I can’t
understand: in order for the embedded forms to work in the base form, I must
enter an additional field-property into the parent entity in order to
subsequently link the collection of child entities through it? Or should I just
modify an existing field in the parent entity for binding? If I understood correctly, then already at the controller level, should I
place the entity object with all entities associated with it
in the $form = $this->createForm(new TaskType(), $task) construct in $task ?
These are the questions and a bunch of
other related questions.
Can you help me figure out these things?
Thank you in advance.
Answer the question
In order to leave comments, you need to log in
<?php
class Entity
{
private $a;
}
class FormType
{
$builder->add('a');
$builder->add('other_form'); // ????
}
Situation (see the code below):
There is an entity Posout (equipment), there are entities Postype (equipment type) and Brand (brand).
The Posout (equipment) entity has ONE-WAY ManyToOne relationships with Postype (equipment type) and Brand (brand), respectively, through the fields:
/**
* @var integer
* @ORM\ManyToOne(targetEntity="Acme\AppBundle\Entity\Postype", inversedBy="postype_id")
* @ORM\JoinColumn(name="postype_id", referencedColumnName="id")
*/
private $postype;
/**
* @var integer
* @ORM\ManyToOne(targetEntity="Acme\AppBundle\Entity\Brand", inversedBy="posbrand_id")
* @ORM\JoinColumn(name="posbrand_id", referencedColumnName="id")
*/
private $posbrand;
...
->add( 'postype', new PostypeType() )
->add( 'posbrand', new BrandType() )
...
<?php
namespace Acme\AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Posout
* @ORM\Table(name="posout")
* @ORM\Entity(repositoryClass="Acme\AppBundle\Repository\PosoutRepository")
*/
class Posout {
/**
* @var integer
* @ORM\Column(name="id", type="bigint", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
...
/**
* @var integer
* @ORM\ManyToOne(targetEntity="Acme\AppBundle\Entity\Postype", inversedBy="postype_id")
* @ORM\JoinColumn(name="postype_id", referencedColumnName="id")
*/
private $postype;
/**
* @var integer
* @ORM\ManyToOne(targetEntity="Acme\AppBundle\Entity\Brand", inversedBy="posbrand_id")
* @ORM\JoinColumn(name="posbrand_id", referencedColumnName="id")
*/
private $posbrand;
...
/**
* Get id
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set postype
* @param integer $postype
* @return Posout
*/
public function setPostype( $postype )
{
$this->postype = $postype;
return $this;
}
/**
* Get postype
* @return integer
*/
public function getPostype()
{
return $this->postype;
}
/**
* Set posbrand
* @param integer $posbrand
* @return Posout
*/
public function setPosbrand( $posbrand )
{
$this->posbrand = $posbrand;
return $this;
}
/**
* Get posbrand_id
* @return integer
*/
public function getPosbrand()
{
return $this->posbrand;
}
...
}
<?php
namespace Acme\AppBundle\Entity;use Doctrine\ORM\Mapping as ORM;
/**
* Postype
* @ORM\Table(name="postype")
* @ORM\Entity
*/
class Postype {
/**
* @var integer
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var integer
* @ORM\Column(name="postype_id", type="integer")
*/
private $postype_id;
/**
* @var string
* @ORM\Column(name="postype_desc", type="string")
*/
private $postype_desc;
/**
* @var string
* @ORM\Column(name="postype_name", type="string")
*/
private $postype_name;
/**
* Get id
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set postype_id
* @param integer $postypeId
* @return Postype
*/
public function setPostypeId($postypeId)
{
$this->postype_id = $postypeId;
return $this;
}
/**
* Get postype_id
* @return integer
*/
public function getPostypeId()
{
return $this->postype_id;
}
...
}
<?phpnamespace Acme\AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Brand
* @ORM\Table(name="brand")
* @ORM\Entity
*/
class Brand {
/**
* @var integer
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var integer
* @ORM\Column(name="posbrand_id", type="bigint")
*/
private $posbrand_id;
/**
* @var string
* @ORM\Column(name="posbrand_name", type="string")
*/
private $posbrand_name;
/**
* Get id
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set posbrand_id
* @param integer $posbrandId
* @return Brand
*/
public function setPosbrandId($posbrandId)
{
$this->posbrand_id = $posbrandId;
return $this;
}
/**
* Get posbrand_id
* @return integer
*/
public function getPosbrandId()
{
return $this->posbrand_id;
}
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question