I'm trying to automatically order the results of a report by the ManyToMany annotation @OrderBy
:
/**
* @ORM\ManyToMany(targetEntity="Artist", inversedBy="soundtrack", cascade={"persist", "remove"})
* @ORM\JoinTable(name="soundtrack_artist")
* @OrderBy({"name" = "ASC", "surname" = "ASC"})
**/
private $artists;
but it gives me this error:
[Semantical Error] The annotation "@OrderBy" in property
Acme\UserBundle\Entity\Soundtrack::$artists was never imported.
Did you maybe forget to add a "use" statement for this annotation?
I tried to add also:
use Doctrine\ORM\Mapping\OrderBy;
But the error remains! I'm doing something wrong?
Not sure if you found the answer, but this worked for me:
@ORM\OrderBy
If you include this namespace:
use Doctrine\ORM\Mapping as ORM;
This annotation will work:
@ORM\OrderBy({"date" = "ASC"})
the first key should be a mapped attribute of your class. The order should be ASC or DESC.
Please refer to Doctrine official documentation: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/annotations-reference.html#annref-orderby
@ORM\OrderBy
resolve all problem, in symfony annotation its important inserting the scope of a method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With