I try to execute this query in my CompanyRepository
$qb = $this->_em->createQueryBuilder();
$qb->select(array('c', 'ld'))
->from('Model\Entity\Company', 'c')
->leftJoin('c.legaldetails', 'ld', \Doctrine\ORM\Query\Expr\Join::ON, 'c.companyid=ld.companyid');
$query = $qb->getQuery();
echo($query->getSQL());
When I try to do it I having error:
Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Syntax Error] line 0, col 69: Error: Expected end of string, got 'ON'' in /home/raccoon/web/freetopay.dev/www/class/new/library/Doctrine/ORM/Query/QueryException.php on line 42
These are my models:
<?php
namespace Model\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Company
*
* @ORM\Table(name="Company")
* @ORM\Entity(repositoryClass="\Model\Repository\CompanyRepository")
*/
class Company
{
/**
* @var integer $companyid
*
* @ORM\Column(name="CompanyID", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $companyid;
/**
* @var \Model\Entity\LegalDetails $legaldetails
*
* @ORM\OneToOne(targetEntity="\Model\Entity\Legaldetails", mappedBy="companyid")
*/
private $legaldetails;
//other fields
public function __construct()
{
$this->legaldetails = new ArrayCollection();
}
//setters and getters
and legaldetails entity:
<?php
namespace Model\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Legaldetails
*
* @ORM\Table(name="LegalDetails")
* @ORM\Entity
*/
class Legaldetails
{
/**
* @var integer $legalid
*
* @ORM\Column(name="LegalID", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $legalid;
/**
* @var \Model\Entity\Company $company
*
* @ORM\Column(name="CompanyID", type="integer", nullable=false)
* @ORM\OneToOne(targetEntity="\Model\Entity\Company", inversedBy="companyid")
* @ORM\JoinColumn(name="companyid", referencedColumnName="companyid")
*/
private $company;
What is wrong?
/** * @var Legaldetails $legaldetail * * @ORM\OneToOne(targetEntity="Legaldetails", mappedBy="company") */ private $legaldetail;
in company entity and/** * @var Company $company * * @ORM\OneToOne(targetEntity="Company") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="CompanyID", referencedColumnName="CompanyID", unique=true) * }) */ private $company;
in legaldetails – Endocardial