Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8713035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:14:45+00:00 2026-06-13T05:14:45+00:00

I have a document that has embedded documents in it but I am getting

  • 0

I have a document that has embedded documents in it but I am getting the “Cannot apply $push/$pushAll modifier to non-array” error even though the data is being persisted.

Here is my document:

/**
 * @MongoDB\EmbeddedDocument
 */
class Author
{
   /**
    * @MongoDB\Int
    */
   protected $id;

   /**
    * @MongoDB\String
    */
    protected $name;
}

Here is my Comment document that embeds the Author document:

/**
 *@MongoDB\Document(collection="discussions")
 */
class Discussion
{

   /**
    * @MongoDB\Id
    */
        protected $id;

    /**
     * @MongoDB\ObjectId
     */
    protected $discussion_id;


   /**
     * @MongoDB\String
     */
    protected $slug;


   /** @MongoDB\EmbedOne(targetDocument="Author") */
    protected $author;

     /**
     * @MongoDB\String
     */
    protected $text;


    /**
     * @MongoDB\Date
     */
    protected $createdAt;
}

And finally here is my listing document that embeds the discussion document

class Listing
{
    /**
     * @MongoDB\Id
     */
    protected $id;

      /** @MongoDB\ReferenceMany(targetDocument="Discussion") */
    protected $discussions;

    public function __construct()
    {
        $this->discussions = new \Doctrine\Common\Collections\ArrayCollection();
    }

     /**
     * Add discussions
     *
     * @param Main\SomeBundle\Document\Discussion $discussions
     */
    public function addDiscussions(\Main\SomeBundle\Document\Discussion $discussions)
    {
        $this->discussions[] = $discussions;
    }

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


}

So in my code I am doing the following to put data in:

 $author = new Author();
         $author->setId( 1 );
         $author->setName("blahblah"); //for now the user name is the author name
         $discussion = new Discussion();
         $discussion->setAuthor($author);
         $dm->persist($discussion);
         $listing->addDiscussions($discussion); <---- I GET THIS HERE!!!!
         $dm->persist($listing);
         $dm->flush();

The error that i am getting is on the line “$listing->addDiscussions($discussion);” because when I remove it, it goes away.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:14:47+00:00Added an answer on June 13, 2026 at 5:14 am

    You are getting that error because you are trying to use your discussions variable as an array, but you have not declared it as such yet. When you declare discussions in the Listing class, you’ll want to declare it as an empty array :

    $discussions = array();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model pretty much like this: Document Release has an embedded array
So I have an embedded document that tracks group memberships. Each embedded document has
I have a document Design.rb that has an embedded document Attachment.rb that does some
I have collection of documents, witch has an array, of embedded documents, how i
I have an object called Document that has a one-to-many relationship with DocumentPersonCc. I
I have a Delphi application that has a document browser as the main form.
I have XML tag that has the content which is HTML document. <xml-tag> <!--
I have a winforms c# app that has an embedded webbrowser control inside it
The sample db that comes with RavenDB has Albums document collection, that each have
Problem: I have a 'Group' collection. Each group has an embedded document of 'Members'.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.