Search code examples
phpsymfonydoctrine-ormaudit-trail

Doctrine changing ID of injected data


I have some injected data to get Doctrine started.

My Member (user) table looks something like

id | first_name | last_name | email | password ...

Data injected as follows:

INSERT INTO member (id, first_name, last_name, email, password) VALUES (1, "Default", "System", "[email protected]", "system_pass")

Running $defaultMember = $repository->findOneBy(array("first_name" => "Default")) yields a Member object, and _em->contains($defaultMember) is true. The object even shows ID of 1 in the debugger. Yet when I make a change: $defaultMember->setFirstName("Default2") and flush back to the database, it tries to insert a new (duplicate) member, with whatever the next id in the sequence is.


Solution

  • Problem was solved with a combination of getter/setter for the id (not sure if this was the underlying problem), and using $this->_em in the repository as opposed to $this->getEntityManager().