0
votes

i want to use this:

$query = $this->_doctrine->createQueryBuilder()
        ->select('u')
        ->from('\Entities\Users', 'l')
        ->leftJoin('l.userentities', 'u')
        ->getQuery();
return $info = $query->getResult();

and my users entity is:

namespace Entities\Users;

/**
 * @Entity
 * @Table(name="users")
 * @HasLifecycleCallbacks
 */
class Users extends \Entities\AbstractEntity
{
    /**
     * @Id @Column(name="userid", type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    protected $userid;
      /** @Column(name="itemid", type="integer") */

    protected $itemid;
}

and my user entities entity class contains:

namespace Entities\Users;

/**
 * @Entity
 * @Table(name="userentities")
 * @HasLifecycleCallbacks
 */
class Userentities extends \Entities\AbstractEntity
{
    /**
     * @Id @Column(name="entityid", type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    protected $entityid;
      /** @Column(name="userid", type="integer") */

    protected $userid;

     /** @Column(name="crb", type="string") */

    protected $crb;

}

i tried put this into the entity but no joy * @OneToMany(targetEntity="Users", inversedBy="userid") * @JoinColumn(name="userid", referencedColumnName="userid")

1 user has many user entities..

and i get this error:

Error: Class Entities\Users has no association named Users

i just want to do a left join with users to usersentities..

how can i doa left join?

1

1 Answers

1
votes

Try putting this annotation in your Userentities class for the $userid field:

/**
 * @var Entities\Userentities
 * @ManyToOne(targetEntity="Users", inversedBy="userentities", cascade={"persist"})
 */
private $userid;

and this annotation in your Users class with a new field called $userentities:

/**
 * @var \Doctrine\Common\Collections\ArrayCollection
 * @OneToMany(targetEntity="Userentities", mappedBy="userid", cascade={"persist", "remove"})
 */
private $userentities;