H
H
HellWalk2019-08-29 13:30:43
symfony
HellWalk, 2019-08-29 13:30:43

How to create a field under the mappedBy="" link?

To make the question more understandable, I’ll tell you a few words about how symphony allows, in the form of creating one entity, to immediately display the form to fill in another, related entity.
Let's say we have a client entity with a passport field. At the same time, the passport is a separate entity with its own parameters.
Entity-level communication:

/**
     * @ORM\ManyToOne(targetEntity="App\Entity\Passport", inversedBy="client", cascade={"persist", "merge"})
     * @ORM\JoinColumn(nullable=false)
     */
    private $passport;

And at the level of the client creation form, this is done easily:
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            // ...
            ->add('passport', PassportType::class)

And now to the essence of the matter - the client also has property (there can be a lot of it), and it is connected like this:
From the client side:
/**
     * @ORM\OneToMany(targetEntity="App\Entity\Property", mappedBy="client")
     */
    private $property;

From the property side:
/**
     * @ORM\ManyToOne(targetEntity="App\Entity\Client", inversedBy="property", cascade={"persist", "merge"})
     * @ORM\JoinColumn(nullable=false)
     */
    private $client;

The automatic crud generator completely ignores the $property property of the client (this is partly understandable, because when mappedBy is associated, no field is created in the client table), but the symphony probably thought of the possibility to indicate to the form that when creating a client, we must immediately create several variants of it property.
Anyone suggest how to do this?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question