-1

well, every user has multiple sports so i have created table users and table sports and table usersport

so i want that the user select multiple sport and store it in table user sport

user entity arrayCollection
/**
 * @ORM\OneToMany(targetEntity="SportUser", mappedBy="user")
 */
private $sports;
public function __construct()
{       
    $this->sports = new ArrayCollection();
}

//usertype

->add('sports', CollectionType::class, [
'entry_type'    => SportType::class,
    'allow_add'     => true,
    'allow_delete'  => true,
 ]) 

i want to make a user form with multi-select from entity sport and store it in table user sport

  • I like multiple sports as well. Might consider updating your question with an actual question. – Cerad Oct 10 '19 at 15:39
  • I don't know what your actual question is, but you might want to read up on [form collections](https://symfony.com/doc/current/form/form_collections.html) and possibly [doctrine associations](https://symfony.com/doc/current/doctrine/associations.html#saving-related-entities). Feel free to ask any concrete questions if you have any, e.g. errors you run into or unexpected behavior. – dbrumann Oct 11 '19 at 04:48

1 Answers1

0

The best thing is to use the EntityType

->add('sports', EntityType::class, [ 'class' => SportType::class, 'choice_label' => 'sport_field' 'multiple' => true ])

Berthol Yvano
  • 306
  • 3
  • 8