Sonata Admin Bundle - sort order of manytoone

2,736 views
Skip to first unread message

Steve Sobel

unread,
Jun 22, 2012, 3:21:23 AM6/22/12
to sonata...@googlegroups.com
Hello,

I'm using the Admin bundle and so far it's great, but I have one problem... I discovered the documentation that allows OneToMany items to be drag/drop sorted from here:

http://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/form_field_definition.html#advanced-usage-one-to-many

The problem is this:

Dragging and dropping to save a new sort order does work - it updates the database properly and they display in the right order on the frontend of my website -- but in the admin, the query doesn't sort them using my displayOrder column, so the order looks wrong on page load even though it properly saved the order I dragged/dropped!

It would seem to me that since I specified which field was the "sortable" field in the spec that it should know to order on that field, shouldn't it?  Is this a bug, or am I perhaps doing something wrong?

Steve

Thomas Rabaix

unread,
Jun 22, 2012, 3:25:01 AM6/22/12
to sonata...@googlegroups.com

You need to specify the collection ordering in the schema definition.

--
You received this message because you are subscribed to the Google Groups "sonata-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sonata-users/-/x8qgy9xeJtwJ.
To post to this group, send email to sonata...@googlegroups.com.
To unsubscribe from this group, send email to sonata-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sonata-users?hl=en.

Steve Sobel

unread,
Jun 22, 2012, 3:35:20 AM6/22/12
to sonata...@googlegroups.com
Thanks, I'll have to look up what that means - I'm pretty new to the bundle...

Can I ask, since you seem to know the bundle: Can I also have
drag/sort on an entity that isn't a onetomany? For example I just
have "Items", no child relationships at all... does the Admin Bundle
support drag/sort on those as long as they have a sortable field? I
didn't see anything in the documentation but I'd love it if this
existed...

Steve

rgv

unread,
Dec 2, 2012, 12:23:57 PM12/2/12
to sonata...@googlegroups.com
I've the same question. I want to sort elements of an entity with an 'order' field with drag&drop, but I don't figure how to do it.

Anyone?

Thanks!

Arthur Voncken

unread,
Sep 27, 2016, 5:52:26 AM9/27/16
to sonata-users
As he never explained and I had to search too, here it what you need  to do.
In the entity, when you define the onetomany relation, you can add an asset orderby

/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Last_edition", mappedBy="homepage", cascade={"all"})
* @ORM\OrderBy({"num_order" = "ASC"})
*/
private $last_editions;

Here we are
Reply all
Reply to author
Forward
0 new messages