Doctrine: Target object cannot be found (two beams)

I'm trying to make a ManyToOne relationship in Symfony2 with Doctrine. My objects:

namespace My\ApiBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
 * @ORM\Entity
 * @ORM\Table(name="company")
 */
class Company
{
    /**
     * @var integer
     *
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    protected $id;

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

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

      

And another:

namespace My\UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Entity\User as BaseUser;

/**
 * User
 *
 * @ORM\Table(name="user")
 * @ORM\Entity
 */
class User extends BaseUser
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @var
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

...

/**
     * @ORM\ManyToOne(targetEntity="My\ApiBundle\Entity\Company")
     * @ORM\JoinColumn(name="idLastCompany", referencedColumnName="id")
     */
    protected $idLastCompany;

      

Obviusly with other attributes and their sets and gets methods, but my only relationship is between the Company with idLastCompany. For example, when I clear the cache, I get this error:

MappingException: The My \ ApiBundle \ Entity \ Copmany object cannot be found under "My \ UserBundle \ Entity \ User # idLastCompany".

Any idea? Thanks to

+3


source to share


1 answer


The error message tells you everything you need :)



MappingException: The My \ ApiBundle \ Entity \ Copmany object could not be found in "My \ UserBundle \ Entity \ User # idLastCompany".
You write Co PM anything other than Company, either in the entity file name, or in the entity class name, or in the $ idLastCompany docblock relationship field.
Although the code you posted here is correct, your actual code contains a typo. I would search the entire project for "Copmany" and correct the typo. Then it will work.

+1


source







All Articles