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

  • SEARCH
  • Home
  • 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 9101183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:03:37+00:00 2026-06-17T01:03:37+00:00

i’m receiving the following error message upon persisting and flushing an object with its

  • 0

i’m receiving the following error message upon persisting and flushing an object with its associations:

Catchable Fatal Error: Argument 1 passed to
Doctrine\Common\Collections\ArrayCollection::__construct() must be of
the type array, object given, called in  
.../vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 519 and defined in 
.../vendor/doctrine/common/lib/Doctrine/Common/Collections/ArrayCollection.php line 48

what i have is a single table inheritance with this as the base object:

use Doctrine\ORM\Mapping as ORM;

/**
 * ObjectData
 *
 * @ORM\Table(name="object_data")
 * @ORM\Entity(repositoryClass="Edexp\CoreBundle\Entity\ObjectDataRepository")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="entity_name", type="string")
 * @ORM\DiscriminatorMap({
 *      "request" = "Edexp\MessageBundle\Entity\RequestData"
 * })
 * @ORM\HasLifecycleCallbacks
 */
class ObjectData
{
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="created_at", type="datetime")
 */
private $created_at;

/**
 * @var User
 *
 * @ORM\OneToMany(targetEntity="User", mappedBy="data")
 */
private $user;

/**
 * @var string
 *
 * @ORM\Column(name="`key`", type="string", length=255)
 */
private $key;

/**
 * @var string
 *
 * @ORM\Column(name="data", type="blob")
 */
private $data;

/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this->id;
}

/**
 * Set created_at
 *
 * @param \DateTime $createdAt
 * @return ObjectData
 */
public function setCreatedAt($createdAt)
{
    $this->created_at = $createdAt;

    return $this;
}

/**
 * Get created_at
 *
 * @return \DateTime
 */
public function getCreatedAt()
{
    return $this->created_at;
}

/**
 * Set user
 *
 * @param User $user
 * @return ObjectData
 */
public function setUser($user)
{
    $this->user = $user;

    return $this;
}

/**
 * Get user
 *
 * @return User
 */
public function getUser()
{
    return $this->user;
}

/**
 * Set key
 *
 * @param string $key
 * @return ObjectData
 */
public function setKey($key)
{
    $this->key = $key;

    return $this;
}

/**
 * Get key
 *
 * @return string
 */
public function getKey()
{
    return $this->key;
}

/**
 * Set data
 *
 * @param string $data
 * @return ObjectData
 */
public function setData($data)
{
    $this->data = $data;

    return $this;
}

/**
 * Get data
 *
 * @return string
 */
public function getData()
{
    return $this->data;
}

/**
 * @ORM\PrePersist
 */
public function prepareForPersist()
{
    $this->created_at = new \DateTime();
}
}

and an additional object that inherits from ObjectData:

use Doctrine\ORM\Mapping as ORM;

use MyProject\CoreBundle\Entity\ObjectData;

/**
* RequestData
*
* @ORM\Entity()
*/
class RequestData extends ObjectData
{
    /**
    * var Request $request
    *
    * @ORM\ManyToOne(targetEntity="Request", inversedBy="data")
    * @ORM\JoinColumn(name="object_id", referencedColumnName="id")
    */
    private $request;

    /**
    * Set request
    *
    * @param Request $request
    * @return RequestData
    */
    public function setRequest($request)
    {
        $this->request = $request;
        return $this;
    }

    /**
    * Get request
    *
    * @return Request
    */
    public function getRequest()
    {
        return $this->request;
    }
}

and here’s the object that utilizes the RequestData entity:

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

/**
* Request
*
* @ORM\Table(name="requests")
* @ORM\Entity(repositoryClass="RequestRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Request
{
    /**
    * @var integer $id
    *
    * @ORM\Column(name="id", type="integer")
    * @ORM\Id
    * @ORM\GeneratedValue(strategy="AUTO")
    */
    private $id;

    /**
    * @var Message $message
    *
    * @ORM\ManyToOne(targetEntity="Message", inversedBy="requests")
    */
    private $message;

    /**
    * @var RequestType $type
    *
    * @ORM\ManyToOne(targetEntity="RequestType")
    * @ORM\JoinColumn(name="type_id", referencedColumnName="id")
    */
    private $type;

    /**
    * @var ArrayCollection $data
    *
    * @ORM\OneToMany(
    *       targetEntity="RequestData",
    *       mappedBy="request",
    *       cascade={"persist","remove"}
    * )
    */
    private $data;

    /**
    * @var datetime $created_at
    *
    * @ORM\Column(name="created_at", type="datetime")
    */
    private $created_at;

    /**
    * @var text $comment
    *
    * @ORM\Column(name="comment", type="text")
    */
    private $comment;

    /**
    * @var ArrayCollection $responses
    *
    * @ORM\OneToMany(
    *       targetEntity="Response",
    *       mappedBy="request",
    *       cascade={"persist","remove"}
    * )
    */
    private $responses;

    public function __construct()
    {
        $this->data      = new ArrayCollection();
        $this->responses = new ArrayCollection();
    }

    /**
    * Get id
    *
    * @return integer
    */
    public function getId()
    {
        return $this->id;
    }

    /**
    * Set message
    *
    * @param Message $message
    */
    public function setMessage($message)
    {
        $this->message = $message;
    }

    /**
    * Get message
    *
    * @return Message
    */
    public function getMessage()
    {
        return $this->message;
    }

    /**
    * Set type
    *
    * @param RequestType $type
    */
    public function setType($type)
    {
        $this->type = $type;
    }

    /**
    * Get type
    *
    * @return RequestType
    */
    public function getType()
    {
        return $this->type;
    }

    /**
    * Set created_at
    *
    * @param datetime $createdAt
    */
    public function setCreatedAt($createdAt)
    {
        $this->created_at = $createdAt;
    }

    /**
    * Get created_at
    *
    * @return datetime
    */
    public function getCreatedAt()
    {
        return $this->created_at;
    }

    /**
    * Set comment
    *
    * @param text $comment
    */
    public function setComment($comment)
    {
        $this->comment = $comment;
    }

    /**
    * Get comment
    *
    * @return text
    */
    public function getComment()
    {
        return $this->comment;
    }

    /**
    * Add response
    *
    * @param Response $response
    */
    public function addResponse($response)
    {
        foreach ( $this->responses as $r ) {
            if ( $r->getUser() == $response->getUser() )
                return;
        }

        $this->responses->add($response);
    }

    /**
    * Get responses
    *
    * @return ArrayCollection
    */
    public function getResponses()
    {
        return $this->responses;
    }

    public function hasResponse($user)
    {
        foreach ( $this->responses as $r ) {
            if ( $r->getUser() == $user )
                return $r;
        }
        return null;
    }

    public function addData($data)
    {
        $data->setRequest($this);
        $this->data->add($data);
    }

    public function getData()
    {
        return $this->data;
    }

    /**
    * @ORM\PrePersist
    */
    public function prePersist()
    {
        $this->created_at = new \DateTime();
    }
}

and finally the code that results in an error:

            use MyProject\MessageBundle\Entity\Request as MyRequest;

    $data = new RequestData();
    $data->setUser($user);
    $data->setKey('user_id');
    $data->setData(6);

    $req = new MyRequest();
    $req->setMessage($message);
    $req->setComment('bla');
    $req->setType($doctrine->getRepository('MessageBundle:RequestType')->find(1));
    $req->addData($data);

    $em->persist($req);
    $em->flush();

any suggestions as to what might be wrong here?

cheers

  • 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-17T01:03:39+00:00Added an answer on June 17, 2026 at 1:03 am

    so here’s what i had to do in order to make it work.

    i had to change the association in ObjectData from:

    @ORM\OneToMany(targetEntity="User", mappedBy="data")
    

    to

    @ORM\ManyToOne(targetEntity="User", inversedBy="data")
    

    added the data field to the User entity accordingly.

    /**
     * @var ArrayCollection $data
     *
     * @ORM\OneToMany(targetEntity="ObjectData", mappedBy="user")
     */
    private $data;
    

    and voila, it worked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
i got an object with contents of html markup in it, for example: string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.