gpt4 book ai didi

zend-framework - doctrine2实体关联有什么问题

转载 作者:行者123 更新时间:2023-12-04 04:29:13 24 4
gpt4 key购买 nike

Elloo,我有两个教义实体,正在尝试进行左连接,但是我收到一条消息“错误:GR \ Entity \ AccountEvents类没有名为Accounts的关联”。我看过其他关于stackoverflow的解决方案,但是没有任何帮助。

这是我的代码

<?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;
}
}


..和

<?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;
}
}


..和我的查询

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


$results = $query->getResult();


提前致谢

最佳答案

我已经解决了,这是下面的解决方案(我正在使用ZF 1.11,准则2和nolasnowball库)

在帐户中实体更改

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


在AccountEvents实体更改中

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


取得结果集

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

$results = $query->getQuery()->getResult();


这是完整的代码 http://pastie.org/3626654

关于zend-framework - doctrine2实体关联有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9755114/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com