2

I want to get a collection of embedded documents. I put data into the database like this:

$dm->getRepository('BundleUserBundle:User')->addRatedPostById($user->getId(), new RatedPost($id, $type));

...which works fine. Now I see new data in mongo console, but when I'm trying to get this data via the getRatedPosts() method, it return null instead of the ArrayCollection. Whats wrong?

Context looks like this:

class User extends BaseUser {
    /**
     * @MongoDB\EmbedMany(targetDocument="RatedPost")
     */
    protected $ratedPosts;

   /**
    * Add ratedPosts
    *
    * @param Bundle\UserBundle\Document\RatedPost $ratedPosts
    */
    public function addRatedPost(\Bundle\UserBundle\Document\RatedPost $ratedPosts)
    {
        $this->ratedPosts[] = $ratedPosts;
    }

   /**
    * Remove ratedPosts
    *
    * @param Bundle\UserBundle\Document\RatedPost $ratedPosts
    */
    public function removeRatedPost(\Bundle\UserBundle\Document\RatedPost $ratedPosts)
    {
        $this->ratedPosts->removeElement($ratedPosts);
    }

   /**
   * Get ratedPosts
   *
   * @return Doctrine\Common\Collections\Collection $ratedPosts
   */
   public function getRatedPosts()
   {
       return $this->ratedPosts;
   }

/**
 * @MongoDB\EmbeddedDocument
 */
class RatedPost
{
    /**
     * @MongoDB\Int
     */
    public $post;

   /**
    * @MongoDB\String
    */
    public $rate;
   ...
}
4

1 に答える 1