我对学说 2 的注释系统有一些问题(我使用集成到 Zend 框架 2 中的 2.3)。在相对简单的关系上我没有问题,但是我有很多级联表,当我调用存储库查找方法时,我在这里得到一个 Class does not exist 错误:
doctrine\orm\lib\Doctrine\ORM\Proxy\ProxyFactory.php:233
数据库架构本身可能存在一些问题,但我无法更改它,我必须从这个数据库制作我的应用程序。
我所有的实体都开始于:
namespace Gcl\Entities;
use Doctrine\ORM\Mapping as ORM;
这是我的一些实体:
T公司Gcl
/**
* TCompanyGcl
*
* @ORM\Table(name="T_COMPANY_GCL")
* @ORM\Entity(repositoryClass="Gcl\Repositories\TCompanyGclRepository")
*/
class TCompanyGcl
{
/**
* @var ArrayCollection $customerAccounts
*
* @ORM\OneToMany(targetEntity="TCustomerAccount", mappedBy="tCompanyGcl")
*/
private $customerAccounts;
TCustomerAccount
/**
* TCustomerAccount
*
* @ORM\Table(name="T_CUSTOMER_ACCOUNT")
* @ORM\Entity
*/
class TCustomerAccount
{
/**
* @var \TCompanyGcl
*
* @ORM\ManyToOne(targetEntity="TCompanyGcl", cascade={"all"}, fetch="EAGER")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="COMPANY_ID", referencedColumnName="COMPANY_ID")
* })
*/
private $tCompanyGcl;
/**
* @var \TPerson
*
* @ORM\ManyToOne(targetEntity="TPerson", cascade={"all"}, fetch="EAGER")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="PERSON_ID", referencedColumnName="PERSON_ID")
* })
*/
private $person;
/**
* @var ArrayCollection $customerSubscriptions
*
* @ORM\OneToMany(targetEntity="TSubscription", mappedBy="customerAccount")
*/
private $customerSubscriptions;
订阅
/**
* TSubscription
*
* @ORM\Table(name="T_SUBSCRIPTION")
* @ORM\Entity(repositoryClass="Gcl\Repositories\TSubscriptionRepository")
*/
class TSubscription
{
/**
* @var \TCustomerAccount
*
* @ORM\ManyToOne(targetEntity="TCustomerAccount", inversedBy="customerSubscriptions")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="CUSTOMER_ACCOUNT_ID", referencedColumnName="CUSTOMER_ACCOUNT_ID")
* })
*/
private $customerAccount;
所以问题是当我做这样的事情时:
$account = $em->getRepository('Gcl\Entities\TCustomerAccount')->find(1);
$account->getSubscriptions();
$account->getCompanyGcl();
它有效,或者当我一直从 TCompanyGcl 订阅时它也有效。但是当我这样做时:
$subscription = $em->getRepository('Gcl\Entities\TSubscription')->find(1);
我收到上述错误。
如果有人对这个问题有丝毫线索,我将非常感谢您的帮助。
编辑: 这是存储库:TCompanyGclRepositories
namespace Gcl\Repositories;
use Doctrine\ORM\EntityRepository;
class TCompanyGclRepository extends EntityRepository
{
/**
* Récupère la liste des sociétés dont le champ passé en paramètre contient la chaîne de caractères passée en paramètre
*
* @param string field nom du champ dans lequel chercher
* @param string search chaîne de recherche
* @return Array company
*/
public function getCompaniesByField($field = 'companyName', $search = '', $return_mode = 'array'){
$qb = $this->_em->createQueryBuilder();
$qb->select('c')
->from('Gcl\Entities\TCompanyGcl', 'c')
->where('UPPER(c.'.$field.') LIKE :search')
->setParameter('search', "%".mb_strtoupper($search,'UTF-8')."%");
if($return_mode=="array"){
$results = $qb->getQuery()->getArrayResult();
$companies = array(0 => "Pas de société");
foreach($results as $result){
$companies[$result['companyId']] = $result;
}
}
else{
$companies = $qb->getQuery()->getResult();
}
return $companies;
}
public function getCustomerAccountPerson($companyId){
$qb = $this->_em->createQueryBuilder();
$qb->select('cust, p, t')
->from('Gcl\Entities\TCustomerAccount', 'cust')
->leftJoin('cust.person', 'p')
->leftJoin('p.typeofcivility', 't')
->where('cust.companyId = :id')
->setParameter('id', $companyId);
return $qb->getQuery()->getResult();
}
}
TSubscription 存储库
namespace Gcl\Repositories;
use Doctrine\ORM\EntityRepository;
class TSubscriptionRepository extends EntityRepository
{
public function getContractTickets($subscription_id){
$qb = $this->_em->createQueryBuilder();
if(!is_array($subscription_id)){
$subscription_id = array($subscription_id);
}
$qb->select('s, t, i, s.itemId, s.subscriptionId, i.printName, t.ticketSerialNumber')
->from('Gcl\Entities\TSubscription', 's')
->innerJoin('s.ticketSerialNumber', 't')
->leftJoin('s.item', 'i')
->add('where', $qb->expr()->in('s.subscriptionId', $subscription_id));
return $qb->getQuery()->getArrayResult();
}
public function getContractVehicles($subscription_id){
$qb = $this->_em->createQueryBuilder();
if(!is_array($subscription_id)){
$subscription_id = array($subscription_id);
}
$qb->select('s, v, tv, s.itemId, i.printName, v.licencePlate, tv.name')
->from('Gcl\Entities\TSubscription', 's')
->innerJoin('s.licencePlate', 'v')
->leftJoin('v.typeOfVehicle', 'tv')
->leftJoin('s.item', 'i')
->add('where', $qb->expr()->in('s.subscriptionId', $subscription_id));
return $qb->getQuery()->getArrayResult();
}
}
我的实体位于文件夹 Gcl/Entities 中,而我的存储库位于 Gcl/Repositories 中。当我从实体中删除一些关联时,我可以调用它们以及它们的方法就好了。但是,如果在 Subscription 存储库上调用 find 方法时,我从 TCustomerAccount 中删除了 tCompanyGcl 和 person 关联,我会收到此错误:
Class Gcl\Entities\ArrayCollection does not exist