1

教義2の注釈システムに問題があります(Zendフレームワーク2に統合した2.3を使用しています)。比較的単純な関係では問題はありませんが、カスケードに多くのテーブルがあり、リポジトリのfindメソッドを呼び出すと、ここでクラスが存在しないというエラーが発生します。

doctrine\orm\lib\Doctrine\ORM\Proxy\ProxyFactory.php:233

データベーススキーマ自体に問題がある可能性がありますが、変更できません。このデータベースからアプリを作成する必要があります。

私のすべてのエンティティは次のように始まります:

namespace Gcl\Entities;
use Doctrine\ORM\Mapping as ORM;

これが私の実体のいくつかです:

TCompanyGcl

    /**
     * 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;

Tサブスクリプション

/**
 * 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();

    }
}

TSubscriptionRepositories

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にあります。エンティティからいくつかの関連付けを削除すると、それらとそのメソッドを正常に呼び出すことができます。しかし、サブスクリプションリポジトリでfindメソッドを呼び出すときに、TCustomerAccountからtCompanyGclと個人の関連付けを削除すると、次のエラーが発生します。

Class Gcl\Entities\ArrayCollection does not exist
4

2 に答える 2

2

私は問題を見つけました、それが私の目の前でとても単純で信じられませんでした。アノテーションを削除することでエラーが削除されたという事実から、ソースはアノテーションであると思いましたが、問題はセッターメソッドにありました。

たとえば、TCustomerのgetCompanyGclメソッド:

/**
 * Set companyGcl
 *
 * @param \TCompanyGcl $companyGcl
 * @return TCustomerAccount
 */
public function setCompanyGcl(\TCompanyGcl $companyGcl = null)
{
    $this->companyGcl = $companyGcl;

    return $this;
}

ただし、機能するには、次のように、パラメータでオブジェクトの名前空間を正確にする必要があります。

/**
 * Set companyGcl
 *
 * @param \TCompanyGcl $companyGcl
 * @return TCustomerAccount
 */
public function setCompanyGcl(\Gcl\Entities\TCompanyGcl $companyGcl = null)
{
    $this->companyGcl = $companyGcl;

    return $this;
}
于 2012-12-21T13:27:44.393 に答える
1

TclCustomerAccountリポジトリが指定されていません。つまり、デフォルトを使用しています。それは完璧に機能するはずです。TCompanyGclからカスタムリポジトリを使用できるかどうかについては言及していません。

私の推測では、カスタムリポジトリへのパスが間違っているか、リポジトリファイル自体でリポジトリのクラス名のスペルが間違っている(またはアノテーションとは異なるスペル)。

さらにヘルプが必要な場合は、リポジトリファイル自体を投稿する必要があります。

編集:

私は注釈が苦手で、使用していません。しかし、私は思う

@var ArrayCollection $customerSubscriptions 

と組み合わせる

namespace Gcl\Repositories; 

このエラーを生成します。次の方法で、アノテーションにArrayCollectionパス全体を指定します。

use Doctrine\Common\Collection\ArrayCollection as ArrayCollection; 

ファイルの先頭またはすべての注釈で個別に

@var Doctrine\Common\Collection\ArrayCollection $customerSubscriptions 

および同様のもの

于 2012-12-20T01:45:28.017 に答える