fzaninotto/Faker — pull request #197 by jpetitcolas (2013-10-23 15:35:25+00:00)
Title: [WIP] Issue with one-to-one nullable relationship

Let's consider the following one-to-one relationship between a user and a project entities:

``` php
class Project
{
/**
* @var User
*
* @ORM\OneToOne(targetEntity="Acme\DemoBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true)
*/
private $user;
}
```

This relationship is optional. Yet, if I generate a single `User` entity and ten `Project` entities, the populator will raise the following error:

> [Symfony\Component\Debug\Exception\ContextErrorException]
Notice: Undefined offset: 1 in /home/jpetitcolas/dev/Faker/src/Faker/ORM/Doctrine/EntityPopulator.php line 116

Indeed, as my relationship is unique, Faker tries to get the following existing inserted entity, even if it does not exist.

This PR checks if the relationship is optional. If so, and if no more entity is available, Faker does not set it.

Still in Work in Progress (WIP) status. Left tasks:

- [x] Update doctrine entity populator
- [ ] Check (and eventually fix) if issue is the same for Propel
- [ ] Check (and eventually fix) if issue is the same for Mandango
- [ ] Update documentation to mention it