Elloo, I have two doctrine entities and am trying to do left join however i’m getting a message “Error: Class GR\Entity\AccountEvents has no association named Accounts”. i have looked at other solutions on stackoverflow however none has helped.
here is my code
<?php
namespace GR\Entity;
/**
*
* @Table(name="accounts")
* @Entity
*/
class Accounts
{
/**
*
* @var integer $id
* @Column(name="id", type="integer",nullable=false)
* @Id
* @GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @Column(type="string",length=255,nullable=false)
* @var string
*/
private $name;
/**
* @Column(type="string",length=255,nullable=false)
* @var string
*/
private $email;
/**
* @Column(type="string",length=255,nullable=false)
* @var string
*/
private $password;
/**
* @Column(type="datetime",nullable=false)
* @var datetime
*/
private $created_at;
/**
* @OneToMany(targetEntity="AccountEvents", mappedBy="Accounts")
*/
private $accountevents;
public function __get($property)
{
return $this->$property;
}
public function __set($property,$value)
{
$this->$property = $value;
}
}
..and
<?php
namespace GR\Entity;
/**
*
* @Table(name="account_events")
* @Entity
*/
class AccountEvents
{
/**
*
* @var integer $id
* @Column(name="id", type="integer",nullable=false)
* @Id
* @GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var Accounts $accounts
*
* @Column(name="account_id", type="integer", nullable=false)
* @ManyToOne(targetEntity="Accounts", inversedBy="accountevents")
* @JoinColumn(name="accounts_id", referencedColumnName="id")
*/
private $accounts;
/**
* @Column(type="string",length=255,nullable=true)
* @var string
*/
private $event;
/**
* @Column(type="datetime",nullable=false)
* @var datetime
*/
private $created_at;
public function __get($property)
{
return $this->$property;
}
public function __set($property,$value)
{
$this->$property = $value;
}
}
..and my query
$query = $this->em->createQueryBuilder()
->select('a, e')
->from('GR\Entity\AccountEvents', 'e')
->leftJoin('e.Accounts', 'a')
->query();
$results = $query->getResult();
Thanks in advance
I have solved it and here is the solution below (i’m using ZF 1.11, doctrine 2 and nolasnowball library)
In Accounts entity change
In AccountEvents entity change
To fetch resultset
here is the full code http://pastie.org/3626654