I created a fixtures for two related entities. When trying to load the fixtures with
php app/console doctrine:fixtures:load
I always get this error:
Fatal error: Class '[MyNamespace]\Entity\ArrayCollection' not found in [...]
It references this bit of code in my entity:
public function __construct()
{
$this->products = new ArrayCollection();
}
When I uncomment the line in the function, all database records and their relations are created fine in my DB (MySQL).
What is going wrong here and what can be done to fix this?
TIA Matt
Additional information:
Entity "Provider"<?php
namespace VS\Journeyro\WebBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Provider
*/
class Provider
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $slug;
/**
* @var string
*/
private $url;
/**
* @var string
*/
private $email;
/**
* @var string
*/
private $phone;
/**
* @var string
*/
private $image;
/**
* @var string
*/
private $description;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return Provider
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set slug
*
* @param string $slug
* @return Provider
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* @return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set url
*
* @param string $url
* @return Provider
*/
public function setUrl($url)
{
$this->url = $url;
return $this;
}
/**
* Get url
*
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* Set email
*
* @param string $email
* @return Provider
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set phone
*
* @param string $phone
* @return Provider
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* @return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set image
*
* @param string $image
* @return Provider
*/
public function setImage($image)
{
$this->image = $image;
return $this;
}
/**
* Get image
*
* @return string
*/
public function getImage()
{
return $this->image;
}
/**
* Set description
*
* @param string $description
* @return Provider
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
public function __toString()
{
return $this->getName();
}
/**
* Add collection of related products
*/
protected $products;
public function __construct()
{
$this->products = new ArrayCollection();
}
/**
* Add products
*
* @param \VS\Journeyro\WebBundle\Entity\Product $products
* @return Provider
*/
public function addProduct(\VS\Journeyro\WebBundle\Entity\Product $products)
{
$this->products[] = $products;
return $this;
}
/**
* Remove products
*
* @param \VS\Journeyro\WebBundle\Entity\Product $products
*/
public function removeProduct(\VS\Journeyro\WebBundle\Entity\Product $products)
{
$this->products->removeElement($products);
}
/**
* Get products
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getProducts()
{
return $this->products;
}
}
Class writing the fixtures for entity Provider
<?php
namespace VS\Journeyro\WebBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Collections\ArrayCollection;
use VS\Journeyro\WebBundle\Entity\Provider;
class LoadProviderData extends AbstractFixture implements OrderedFixtureInterface
{
/**
* {@inheritDoc}
*/
public function load(ObjectManager $manager)
{
$providers = array();
// defining fixtures in $providers here
foreach ($providers as $record) {
$provider= new Provider();
$provider->setName($record['name']);
$provider->setSlug($record['slug']);
$provider->setUrl($record['url']);
$provider->setEmail($record['email']);
$provider->setImage($record['image']);
$provider->setDescription($record['description']);
$manager->persist($provider);
$manager->flush();
$this->addReference('provider-'.$record['slug'], $provider);
}
}
/**
* {@inheritDoc}
*/
public function getOrder()
{
return 1;
}
}