I have an existing ZF2 project to which I have added entities before, and I have just added a new entity by copying an existing one and changing the details as necessary. This UserCmsPermission
entity links to the User
entity via the User
entity's cmsPermissions
property.
I have redeployed the database using the following commands:
doctrine-module orm:schema-tool:drop --force
doctrine-module orm:schema-tool:create
doctrine-module data-fixture:import
This executes successfully with no errors at all. However, when I access my application I receive the following error:
The target-entity Application\\Entity\\UserCmsPermission cannot be found in
'Application\\Entity\\User#cmsPermissions'.
The relevant code from each entity is as follows:
<?php
/**
* User model
*
*
*/
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Tilt\Entity\Base\User as TiltUser;
/**
* @ORM\Entity
*/
class User extends TiltUser
{
// … etc …
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="UserChallenge", mappedBy="user", cascade={"all"})
*/
protected $challenges;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="UserCmsPermission", mappedBy="user", cascade={"all"})
*/
protected $cmsPermissions;
// … etc …
}
<?php
/**
* User CMS Permission model
*
*
*/
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Tilt\Exception\InvalidArgumentException;
use Tilt\Entity\Base\Entity as BaseEntity;
/**
* @ORM\Entity
*/
class UserCmsPermission extends BaseEntity
{
// … etc …
/**
* @var User
*
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
* @ORM\ManyToOne(targetEntity="User", inversedBy="cmsPermissions", cascade={"all"})
*/
protected $user;
// … etc …
}
As far as I can tell, the code is correct, and I have also removed data/DoctrineORMModule/
in case the entity metadata was being cached, but this hasn't fixed the problem, and neither has restarting PHP5-FPM in case something was being cached there, so I've now run out of ideas.
Anyone got a clue as to what could be causing this to happen?
Finally figured out what is causing this. Doctrine throws this error if you are using a class map to load classes rather than the standard ZF2 autoloader and you've forgotten to update your class map, which was what I'd not done.
Simply running this in the project folder fixed it:
php vendor/zendframework/zendframework/bin/classmap_generator.php
Et voila.