我想用这个:
$query = $this->_doctrine->createQueryBuilder()
->select('u')
->from('\Entities\Users', 'l')
->leftJoin('l.userentities', 'u')
->getQuery();
return $info = $query->getResult();
我的用户实体是:
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;
}
我的用户实体实体类包含:
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;
}
我尝试将此放入实体但没有快乐 * @OneToMany(targetEntity =" Users",inversedBy =" userid") * @JoinColumn(name =" userid",referencedColumnName =" userid")
1个用户拥有许多用户实体..
我收到此错误:
错误:类实体\用户没有名为Users
的关联我只想与用户进行左连接到用户实体..
我怎么能离开加入?
答案 0 :(得分:1)
尝试在$ userid字段的Userentities类中添加此注释:
/**
* @var Entities\Userentities
* @ManyToOne(targetEntity="Users", inversedBy="userentities", cascade={"persist"})
*/
private $userid;
并在您的Users类中使用名为$ userentities的新字段
进行此注释/**
* @var \Doctrine\Common\Collections\ArrayCollection
* @OneToMany(targetEntity="Userentities", mappedBy="userid", cascade={"persist", "remove"})
*/
private $userentities;