1
votes

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?

1
What does setStatus do? Why do you think it's problem related to user-task relationship? - Damian Polac
From where status came ? :p you were talking about user and task, and suddenly asking question regarding status :p , it make confusion. - vivex

1 Answers

3
votes

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.