Vote count:
0
I'm using Doctrine2 inside Symfony and I have the following setup:
An Item class:
/**
* Class Item
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="OneShortly\CommonBundle\Entity\ItemRepository")
*/
class Item
{
/**
* @ORM\ManyToOne(targetEntity="Category")
* @ORM\JoinColumn(name="primaryCategory", referencedColumnName="foreignId")
*/
private $primaryCategory;
}
And a Category class:
/**
* Category
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="OneShortly\CommonBundle\Entity\CategoryRepository")
*/
class Category
{
/**
* @var integer
*
* @ORM\Column(name="foreignId", type="integer", unique=true)
*/
private $foreignId;
}
Now when I do this:
$item = new Item();
$item->setPrimaryCategory($category);
$this->em->persist($item);
$this->em->flush();
I get this error:
[Symfony\Component\Debug\Exception\ContextErrorException] Notice: Undefined index: foreignId in home/www/project/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 692
Now, I've been looking at this from all angles and still cannot see what is wrong with this code. Can you help?
asked 17 secs ago
Aucun commentaire:
Enregistrer un commentaire