L01C
L01C

Reputation: 753

Symfony3 Persist each ManytoOne entities fields in one form?

I have a many to one relation where a User works for an Editor, so an Editor can have many users.
I want to display a form to register a new User, in this form the user type his name,email etc, but also Editor informations, like companyName, number of employees etc.

My User form works well alone, I just don't know how to add Editor input fields. I tried EntityType but it just loads existing entities, and collectionType but it doesn't work(it only displays the label "editoreditor").

Class User
{

...

/**
 * @var \test\EditorBundle\Entity\Editor
 *
 * @ORM\ManyToOne(targetEntity="test\EditorBundle\Entity\Editor")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="editor_ideditor", referencedColumnName="ideditor")
 * })
 */
private $editoreditor;

...

}

Upvotes: 0

Views: 29

Answers (1)

L01C
L01C

Reputation: 753

Answer: In the FormType, just add a field with the other entity FormType as type:

class RegistrationType extends AbstractType

{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {

        $builder                        
    ->add('editoreditor',EditorType::class)

        ;

Upvotes: 0

Related Questions