Search code examples
phpsymfonydoctrine-odm

Doctronie 2 ODM MongoDB Sort in Annotations


I try to sort my query directly with annotations as it is done by ORM with MongoDB.

/**
 * @ORM\OrderBy({"position" = "ASC"})
 */

I use a @MongoDB\ReferenceMany:

class page{
  /**
   * @MongoDB\ReferenceMany(
   *     targetDocument="Project\PageBundle\Document\Contenu",
   *     cascade="all",
   *     sort={"position"="ASC"}
   * )
   */
  $protected contenus;
  public function getContenus(){
      return $this->contenus;
  }
}

When I make a $page->getContenus(); call the MongoDB query is working but the listing is not sorted. I cleared the cache but it doesn't help.

What can I do?


Solution

  • Thanks Jamie Sutherland it's work. I should to add mappedBy.