I have a simple query
$query = $em->createQuery(''
. 'SELECT c.id, c.firstname, c.lastname, coun.country '
. 'FROM OandPboBundle:Clients c '
. 'JOIN OandPboBundle:Countries coun WITH coun.id = c.country '
. 'WHERE c.id = ?1'
)
->setParameter(1, $id)
->setMaxResults(1);
$result = $query->getResult();
As you see it's a Clients entity with a onetoone relation with a Countries entity. So I have a country_id field in my clients table. But the country is a null field, country is not required so the country_id field may be NULL.
So when I execute my query, the query returns NO LINE when there is no country (NULL). Because the left join doesn't exist. And it returns a line of course when there is a country.
How can I do, so the query returns a CLIENT row even if there is no country?
Thank you everybody by advance
In case of I put the CLIENTS entity
class Clients
{
/**
* @ORM\OneToOne(targetEntity="OandP\boBundle\Entity\Countries", cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private $country = null;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
}
And the COUNTRIES entity
class Countries
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="code", type="string", length=2)
*/
private $code;
/**
* @var string
*
* @ORM\Column(name="country", type="string", length=255)
*/
private $country;