Sonataadminbundle: sonata_type_collection initial sort by position

Created on 15 Dec 2012  路  4Comments  路  Source: sonata-project/SonataAdminBundle

Hi,

if I use sonata_type_collection like this:

        $formMapper
            ->add('galleryHasMedias', 'sonata_type_collection', array(
                'by_reference' => false,
                'label' => 'Attached Media'
            ), array(
                'edit' => 'inline',
                'inline' => 'table',
                'sortable'  => 'position',
                'link_parameters' => array('context' => 'amenity')
            ))

Changing sorting and updating object works. The problem is that when I open an Edit form and there is a list of galleryHasMedias it's not sorted by current position values. So actually I don't know what position has each of the object.

critical

Most helpful comment

thomas2411, i think you just need to add

  • @ORM\OrderBy({"position" = "ASC"})
    to your OneToMany relation in entities.
    For me it works fine.

All 4 comments

Cannot reproduce the current code with the SonataMediaBundle works fines.

thomas2411, i think you just need to add

  • @ORM\OrderBy({"position" = "ASC"})
    to your OneToMany relation in entities.
    For me it works fine.

Indeed it worked shtumi :) Thank you very much. Although I have used YML mapping:

oneToMany:
    galleryHasMedias:
        targetEntity: PhotoGalleryMedia
        mappedBy: gallery  
        cascade: ["persist", "remove"]
        orphanRemoval: true
        orderBy: {position: ASC}

Omg... thanks @shtumi

Was this page helpful?
0 / 5 - 0 ratings