Symfony2 Sonata Project sonata_type_model with OneToMany entity sortby

I work with Symfony2 and sonata admin. I have an entity (News) which own a subcategory. Each subcategory own one category, and each category own one Affaire.
In the add page for a news, I have a subcategory list, to choose my subcategory to link to my news. Each item of my select is formated like this :

enter image description here

<li> subcategory (category'affaire) > categoryName </li>.

I would like to sort the fields by the category’s affaire (ASC).

Here is my formfield definition :

protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('subCategory', 'sonata_type_model', array("label" => "Catégorie/Sous Catégorie", "btn_add" => false));
}

One News own one Subcategory

One Subcategory own one Category

One category own one Affaire.

I tried to add something like :

    ->add('subCategory', 'sonata_type_model', 
            array("label" => "Sub Category",
                  "btn_add" => false
            ), 
            array(
                'sortable'      => 'ordering',
                'label'         => 'subcategory.category.affaire.code',
            ))

But nothing changes. Any Ideas ?

Category entity :

class NewsCategory
{
    /**
     * @var \Adexos\Loreal\SapBundle\Entity\Affaire
     *
     * @ORM\ManyToOne(targetEntity="\Adexos\Loreal\SapBundle\Entity\Affaire")
     * @ORM\JoinColumn(name="affaire_code", referencedColumnName="code")
     */
    private $affaire;


Subcategory entity :

class NewsSubCategory
{
    /**
     * @var \Adexos\Loreal\UpBundle\Entity\NewsCategory
     *
     * @ORM\ManyToOne(targetEntity="\Adexos\Loreal\UpBundle\Entity\NewsCategory")
     * @ORM\JoinColumn(name="category_ref", referencedColumnName="id")
     * 
     */
    private $category;


News entity :

class News
{
    /**
     * @var \Adexos\Loreal\UpBundle\Entity\NewsSubCategory
     *
     * @ORM\ManyToOne(targetEntity="\Adexos\Loreal\UpBundle\Entity\NewsSubCategory")
     * @ORM\JoinColumn(name="sub_category", referencedColumnName="id")
     */
    private $subCategory;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s