Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine 2, one to many relationship OrderBy Annotations

Tags:

doctrine-orm

Hello I have got this php order by annotations on my one to many relationship

 /**
  * TaskCategory
  *
  * @Table(name="task_category")
  * @Entity(repositoryClass="models\Repositories\TaskCategoryRepository")
  */
class TaskCategory
{
 /**
  * @var array $tasks
  *
  * @OneToMany(targetEntity="Task", mappedBy="taskCategory"")
  * @OrderBy({"sort_order" = "ASC"})
  */
  private $tasks;

And I got this error:

Uncaught exception 'Doctrine\Common\Annotations\AnnotationException' with message '[Syntax Error] Expected Doctrine\Common\Annotations\Lexer::T_CLOSE_PARENTHESIS, got 'order' at position 108

Anyone got similar issue? Any advise will be greatly appreciated.

like image 714
Vincent Avatar asked Dec 12 '22 10:12

Vincent


2 Answers

The correct annotation is

@OrderBy({"name" = "ASC"})

See: Doctrine 2 manual: Annotations reference

like image 182
Jani Hartikainen Avatar answered Dec 28 '22 22:12

Jani Hartikainen


oops sorry I think I know the mistake it it's the double quote @OneToMany(targetEntity="Task", mappedBy="taskCategory"") suppose to be @OneToMany(targetEntity="Task", mappedBy="taskCategory")

thanks for the answer anyway.

like image 30
Vincent Avatar answered Dec 28 '22 23:12

Vincent