Reputation: 1500
I have a bidirectional association between entity "Task" and entity "User".
"Task" is defined as follows
class Task { /** * * @ORM\ManyToOne(targetEntity="User", inversedBy="tasks") */ private user; }
And "User" is defined as
class User
{
/**
* @ORM\OneToMany(targetEntity="Task", mappedBy="user")
*/
private $tasks;
}
Accessing relationship from both directions works fine. The problem is that I can't update the "Task" entity once it's defined.
Here is a test case
$task->setStatus(new Status(2))
$em->flush();
What am I doing wrong?
Upvotes: 1
Views: 231
Reputation: 3500
You need to persist the task object before flush like this: $em->persist($task);
then you'll be able to flush.
Read how to work with doctrine associations.
Upvotes: 3