What is wrong with doctrine2 entity merging

Elloo, I have two doctrine objects, and I'm trying to make a left join, but I get the message "Error: class GR \ Entity \ AccountEvents does not have an association with the name Accounts". I looked at other solutions in stackoverflow, but none of them 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 request

 $query = $this->em->createQueryBuilder() ->select('a, e') ->from('GR\Entity\AccountEvents', 'e') ->leftJoin('e.Accounts', 'a') ->query(); $results = $query->getResult(); 

Thanks in advance

+4
source share
1 answer

I solved it and here is the solution below (I use ZF 1.11, Doctrine 2 and the nolasnowball library)

In changing the essence of accounts

 /** * @OneToMany(targetEntity="AccountEvents", mappedBy="accounts") * @var \Doctrine\Common\Collections\Collection */ private $accountevents; 

In changing an AccountEvents object

 /** * @ManyToOne(targetEntity="Accounts") * @JoinColumn(name="accounts_id", referencedColumnName="id") * @var GR\Entity\Accounts **/ private $accounts; 

To get the results

 $query = $this->em->createQueryBuilder() ->select('a, e') ->from('GR\Entity\Accounts', 'a') ->leftJoin('a.accountevents', 'e'); $results = $query->getQuery()->getResult(); 

here is the full code http://pastie.org/3626654

+3
source

Source: https://habr.com/ru/post/1402043/


All Articles