Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annotation @OrderBy

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?

like image 598
Lughino Avatar asked Aug 12 '13 14:08

Lughino


3 Answers

Not sure if you found the answer, but this worked for me:

@ORM\OrderBy

like image 116
Prasad Avatar answered Oct 04 '22 18:10

Prasad


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

like image 25
Benjamin Ellis Avatar answered Oct 04 '22 18:10

Benjamin Ellis


@ORM\OrderBy resolve all problem, in symfony annotation its important inserting the scope of a method.

like image 34
Scuottolinx Avatar answered Oct 04 '22 19:10

Scuottolinx