When you want to insert an Entity you do this:
$user = new User();
$user->setEmail('john@doe.com');
$em->persist($user);
$em->flush();
But what if I want to create an article which can have one User;
Currently, I need to do:
$user = $em->getRepository('User')->find($id);
$article->setUser($user);
This is because of the relationship, Doctrine 2 asks for an User entity.
However, I can't "mock" an User object, because I don't want the id be set manually, therefore I can't do:
$user = new User();
$user->setId(45);
Am I wrong about this behavior, how do you do?
It can be performance matter to load the User entity just to set the relationship, even with a cache, which cannot be always an option, especially for an update.