many to many and sonata form types

706 views
Skip to first unread message

Gabriel Richards

unread,
Jan 12, 2013, 3:06:39 AM1/12/13
to sonata...@googlegroups.com
Hello.

SonataAdminBundle is doing just fine for me with many to many relationships if I don't specify a type in the form mapper and just accept the default multi-selects.

However, I want that nifty "Add New" button and its functionality... so like my one to many and many to one relationships, I'd like to use sonata_type_model or sonata_type_collection.

If I use sonata_type_collection I get an error "INVALID MODE", if I use sonata_type_model, I get "No Entity Manager defined..." I suspect because we're dealing with an ArrayCollection here not a single Entity.

Any tips or advice for getting the most user friendly interface for managing many to many with SonataAdminBundle?

TY,
Gabe

Branislav Belohorec

unread,
Sep 13, 2015, 4:57:37 PM9/13/15
to sonata-users
Hi gabe, may I know how you have solved this issue. Because I've got same issue. Thank you

Gabriel Richards

unread,
Sep 13, 2015, 11:12:24 PM9/13/15
to sonata...@googlegroups.com

Hi Branislav.

What is the issue?

G

On Sep 13, 2015 1:57 PM, "Branislav Belohorec" <bbelo...@gmail.com> wrote:
Hi gabe, may I know how you have solved this issue. Because I've got same issue.  Thank you

--
You received this message because you are subscribed to a topic in the Google Groups "sonata-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonata-users/sg1kueeq7Wk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonata-users...@googlegroups.com.
To post to this group, send email to sonata...@googlegroups.com.
Visit this group at http://groups.google.com/group/sonata-users.
For more options, visit https://groups.google.com/d/optout.

Branislav Belohorec

unread,
Sep 14, 2015, 4:00:54 AM9/14/15
to sonata-users
Hi Gabriel, 

I wrote about functionality of sonata_type_model_list (attachment - sonaty_type_model_list.png ) which works for OneToMany resp. ManyToOne enitity property but it doesn't works for ManyToMany.

 I want to have the multiple select from ManyToMany in popup window which shows list of entities with filter grid (attachment  - sonaty_type_model_list_2.png ).



persons property is ManyToMany


                ->add('persons', 'sonata_type_model_list', array(
                        'label' => 'Persons',
                        'required' => false,
                        'btn_add' => 'Add new person', //Specify a custom label
                        'btn_list' => 'Select persons from the list', //which will be translated
                        'btn_delete' => false, //or hide the button.
                            ), array(
                        'placeholder' => 'No selected'
                    ))


I've got error.

No entity manager defined for class Doctrine\Common\Collections\ArrayCollection



Conclusion: I want to apply the functionality of sonata_type_model_list form type for ManyToMany property.
sonaty_type_model_list.png
sonaty_type_model_list_2.png

Branislav Belohorec

unread,
Sep 14, 2015, 4:27:38 AM9/14/15
to sonata...@googlegroups.com

Branislav Belohorec

unread,
Sep 14, 2015, 4:28:04 AM9/14/15
to sonata-users

Gabriel Richards

unread,
Sep 14, 2015, 11:39:51 AM9/14/15
to sonata...@googlegroups.com
I see.

Well... I think there is not a solution exactly like you imagine... instead, you should create an Entity Reference class, and create two ManyToOne relationships to that EntityRef class from the Entities you wish to relate.

Then, in Sonata, use sonata_type_collection and add the Ref class into the FormMapper from whatever Admin class you wish to define the relationship.

You'll need an Admin class for your Ref class... and you may need to set the relationship in the Admin class' prePersist method.

G
--


400 S. Crenshaw Blvd. Suite 100, Torrance, CA 90503

Connect with Us!     Twitter  |  LinkedIn
Reply all
Reply to author
Forward
0 new messages