我有三个表team
,groups
和group_team
。 group
有oneToMany
group_team
,team
有OneToOne
group_team
。一个团队可以拥有多个团队,一个团队只能属于一个团队。这是我的数据库设计
如何在数据库中同时创建oneToMany
记录的同时,将组和团队的groups
关系保持在第三个表中
这里是组实体表单类型
class GroupsType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('team', 'entity', array(
'class' => 'CricketBundle\Model\Entity\Team',
'query_builder' => function(\Doctrine\ORM\EntityRepository $er) {
return $er->createQueryBuilder('t')
->groupBy('t.team')
->orderBy('t.team', 'ASC');
},
'choice_label' => 'team',
'multiple' => true,
'expanded' => true,
'required' => false
))
->add('groupname')
;
}
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults(array(
'data_class' => 'CricketBundle\Model\Entity\Groups'
));
}
}
这里是组实体表单的呈现方式