I am getting this error while trying to load my page(Symfony 3.3):
Catchable Fatal Error: Argument 1 passed to Doctrine\Common\Collections\ArrayCollection::__construct() must be of the type array, object given`.
I have looked at many websites but none of them was able to solve my problem.
Below is an example of my entities:
Setting.php
<?php
namespace PressferBundle\Entity\Pressfer;
use Doctrine\ORM\Mapping as ORM;
/**
* Setting
*
* @ORM\Table(name="pressfer_setting")
* @ORM\Entity(repositoryClass="PressferBundle\Repository\Pressfer\SettingRepositor
y")
*/
class Setting
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var bool
*
* @ORM\Column(name="value", type="boolean")
*/
private $value;
/**
* @ORM\OneToMany(targetEntity="PressferBundle\Entity\Pressfer\Config",
mappedBy="Setting")
*
*/
private $config;
/**
* @ORM\ManyToOne(targetEntity="PressferBundle\Entity\Company\Company",
inversedBy="settings")
* @ORM\JoinColumn(name="company_id", referencedColumnName="id",
onDelete="CASCADE")
*/
private $company;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Setting
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set value
*
* @param boolean $value
*
* @return Setting
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* Get value
*
* @return bool
*/
public function getValue()
{
return $this->value;
}
/**
* Set config
*
* @param string $config
*
* @return Setting
*/
public function setConfig($config)
{
$this->config = $config;
return $this;
}
/**
* Get config
*
* @return string
*/
public function getConfig()
{
return $this->config;
}
/**
* Set company
*
* @param string $company
*
* @return Setting
*/
public function setCompany($company)
{
$this->company = $company;
return $this;
}
/**
* Get company
*
* @return string
*/
public function getCompany()
{
return $this->company;
}
/**
* Constructor
*/
public function __construct()
{
$this->config = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add config
*
* @param \PressferBundle\Entity\Pressfer\Config $config
*
* @return Setting
*/
public function addConfig(\PressferBundle\Entity\Pressfer\Config $config)
{
$this->config[] = $config;
return $this;
}
/**
* Remove config
*
* @param \PressferBundle\Entity\Pressfer\Config $config
*/
public function removeConfig(\PressferBundle\Entity\Pressfer\Config
$config)
{
$this->config->removeElement($config);
}
}
Company.php
<?php
namespace PressferBundle\Entity\Company;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="pf_companies")
*/
class Company
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $email;
/**
* @ORM\Column(type="string", nullable=false)
*/
private $subdomain;
/**
* @ORM\ManyToOne(targetEntity="CompanyInfo")
* @ORM\JoinColumn(name="infoId", referencedColumnName="id", onDelete="CASCADE")
*/
private $infoid;
/**
* @ORM\OneToMany(targetEntity="PressferBundle\Entity\Pressfer\Setting", mappedBy="company", cascade={"persist","remove"})
*/
private $settings;
/**
* @return mixed
*/
public function getInfoId()
{
return $this->infoid;
}
/**
* @param mixed $infoId
*/
public function setInfoId($infoid)
{
$this->infoid = $infoid;
}
/**
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @param mixed $email
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* @return mixed
*/
public function getSubdomain()
{
return $this->subdomain;
}
/**
* @param mixed $subdomain
*/
public function setSubdomain($subdomain)
{
$this->subdomain = $subdomain;
}
/**
* @return mixed
*/
public function getEmail()
{
return $this->email;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* Constructor
*/
public function __construct()
{
$this->settings = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add setting
*
* @param \PressferBundle\Entity\Pressfer\Setting $setting
*
* @return Company
*/
public function addSetting(\PressferBundle\Entity\Pressfer\Setting $setting)
{
$this->settings[] = $setting;
return $this;
}
/**
* Remove setting
*
* @param \PressferBundle\Entity\Pressfer\Setting $setting
*/
public function removeSetting(\PressferBundle\Entity\Pressfer\Setting $setting)
{
$this->settings->removeElement($setting);
}
/**
* Get settings
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getSettings()
{
return $this->settings;
}
}
Config.php
<?php
namespace PressferBundle\Entity\Pressfer;
use Doctrine\ORM\Mapping as ORM;
/**
* Config
*
* @ORM\Table(name="pressfer_config")
*@ORM\Entity(repositoryClass="PressferBundle\Repository\Pressfer\ConfigRepository")
*/
class Config
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var bool
*
* @ORM\Column(name="value", type="boolean")
*/
private $value;
/**
* @ORM\OneToMany(targetEntity="PressferBundle\Entity\Pressfer\Config", mappedBy="dependency")
*/
private $dependency;
/**
* @ORM\ManyToOne(targetEntity="PressferBundle\Entity\Pressfer\Setting", inversedBy="config")
*/
private $Setting;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Config
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set value
*
* @param boolean $value
*
* @return Config
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* Get value
*
* @return bool
*/
public function getValue()
{
return $this->value;
}
/**
* Set dependency
*
* @param string $dependency
*
* @return Config
*/
public function setDependency($dependency)
{
$this->dependency = $dependency;
return $this;
}
/**
* Get dependency
*
* @return string
*/
public function getDependency()
{
return $this->dependency;
}
/**
* Constructor
*/
public function __construct()
{
$this->dependency = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add dependency
*
* @param \PressferBundle\Entity\Pressfer\Config $dependency
*
* @return Config
*/
public function addDependency(\PressferBundle\Entity\Pressfer\Config $dependency)
{
$this->dependency[] = $dependency;
return $this;
}
/**
* Remove dependency
*
* @param \PressferBundle\Entity\Pressfer\Config $dependency
*/
public function removeDependency(\PressferBundle\Entity\Pressfer\Config $dependency)
{
$this->dependency->removeElement($dependency);
}
/**
* Set setting
*
* @param \PressferBundle\Entity\Pressfer\Setting $setting
*
* @return Config
*/
public function setSetting(\PressferBundle\Entity\Pressfer\Setting $setting = null)
{
$this->Setting = $setting;
return $this;
}
/**
* Get setting
*
* @return \PressferBundle\Entity\Pressfer\Setting
*/
public function getSetting()
{
return $this->Setting;
}
}
As I expected it was something very small that was causing it. In my controller I was using setConfig to add data but instead I should have used the addConfig automatically generated by Doctrine.