I'm using KnpPaginatorBundle in a Symfony2 Project. I got 2 Entities with a manyToOne Relationship.
/**
* @ORM\Entity
* @ORM\Table(name="foo")
*/
class foo {
...
/**
* @ORM\ManyToOne(targetEntity="abc\DemoBundle\Entity\Bar")
* @ORM\JoinColumn(name="bar_id", referencedColumnName="id")
*/
protected $bar;
...
}
/**
* @ORM\Entity
* @ORM\Table(name="bar")
*/
class Bar {
...
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
protected $name;
...
}
Now I want to sort with the KnpPaginatorBundle
<{{ entities.sortable('bar', 'i.bar')|raw }}
I get following error message
There is no such field [bar] in the given Query component, aliased by [i]
Is there any way to make bar in foo sortable using bar.name?
Cheers
I believe that sortable takes a label and a column. So you're probably looking for
You have to JOIN the table in the query you are giving to the KnpPaginatorBundle
Now you can sort with the following: