Symfony2 Form Builder Select Across Join Table with Metadata

后端 未结 3 2051
广开言路
广开言路 2021-02-03 12:40

I have 3 entities:

[Member] ----OneToMany----> [MemberCategory] ---ManyToOne---> [Category]

This works well as far as fetching results fr

3条回答
  •  旧巷少年郎
    2021-02-03 13:12

    You will need to use the querybuilder inside your form

    $builder->add('categories', 'entity', array(
            'class' => 'SMWMemberBundle:MemberCategory',
            'property'     => 'category.categoryName',
            'query_builder' => function(EntityRepository $er ) use ( ? ) {
               return $er->createQueryBuilder( ? )
    
              // your query with a left join probably
    
             }
            'multiple'     => true,
            'expanded'     => true,
            'required' => false
        ));
    

    See documentation for proper use. see symfony2 form querybuilder with parameters for an exmple

提交回复
热议问题