I'm trying to create association from my entity 'Entry' to entity FosUserUser. I created table Entry in database and relation to fos_user_user and then doctrine generated entities by: php app/console doctrine:mapping:import AcmeDemoBundle annotation php app/console doctrine:generate:entities AcmeDemoBundle
Generated entity in shortcut:
/**
* Entries
*
* @ORM\Table(name="entry", indexes={@ORM\Index(name="user_id", columns={"user_id"})})
* @ORM\Entity
*/
class Entry {
.............
/**
* @var \FosUserUser
*
* @ORM\ManyToOne(targetEntity="FosUserUser")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
* })
*/
private $user;
/**
* Set user
*
* @param \Acme\DemoBundle\Entity\FosUseUser $user
*/
public function setUser(\Acme\DemoBundle\Entity\FosUseUser $user = null)
{
$this->user = $user;
return $this;
}
}
Doctrine generated entity with setUser(\Acme\DemoBundle\Entity\Entry $user = null) and i changed it to setUser(\Acme\DemoBundle\Entity\FosUseUser $user = null).
Now Im trying to create object Entry public function addEntryAction() {
$em = $this->getDoctrine()->getManager();
$user = $this->getDoctrine()->getRepository('AcmeDemoBundle:FosUserUser')->find($this->getUser()->getId());
$new_entry = new Entry;
$new_entry->setEntry('test');
$new_entry->setUser($user);
$em->persist($new_entry);
$em->flush();
End the problem is that Symfony doesnt match my entities and respond error Found entity of type Acme\DemoBundle\Entity\FosUserUser on association Acme\DemoBundle\Entity\Entry#user, but expecting Acme\DemoBundle\Entity\Entry
Is it association created corectly or where is the problem?
\Acme\DemoBundle\Entity\FosUseUser
class correct? You're talking about someFosUserUser
class but type hinting asFosUseUser
class insetUser
method.. – xurshid29