我有一個相當奇怪的問題。我在Zend Framework 1.11下使用Doctrine 2。我有一個名爲「Sessions」的數據庫,這是針對學生的培訓課程。每個會話都有一個相關的註釋,稱爲SOAPE註釋。編輯:我現在包括兩個有問題的實體。Zend錯誤中的Doctrine 2:Class Entities X沒有名爲Entities的關聯 Y
會議:
use Doctrine\ORM\Mapping as ORM;
/**
* @Entity(repositoryClass="Repositories\Sessions")
* @Table(name="Sessions")
*/
class Sessions
{
/**
* @var integer Id
*
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var integer $schId
*
* @Column(name="schId", type="integer", nullable=false)
*/
protected $schId;
/**
* @var integer $stdId
*
* @Column(name="stdId", type="integer", nullable=false)
*/
protected $stdId;
/**
* @var integer $trainerPsnId
*
* @Column(name="trainerPsnId", type="integer", nullable=false)
*/
protected $trainerPsnId;
/**
* @var boolean $isLegacy
*
* @Column(name="isLegacy", type="boolean", nullable=false)
*/
protected $isLegacy;
/**
* @var float $charge
*
* @Column(name="charge", type="float", nullable=false)
*/
protected $charge;
/**
* @var float $trainerPay
*
* @Column(name="trainerPay", type="float", nullable=false)
*/
protected $trainerPay;
/**
* @var integer $modeId
*
* @Column(name="modeId", type="integer", nullable=false)
*/
protected $modeId;
/**
* @var text $notes
*
* @Column(name="notes", type="text", nullable=true)
*/
protected $notes;
/**
* @var string $twitterNote
*
* @Column(name="twitterNote", type="string", length=20, nullable=true)
*/
protected $twitterNote;
// ASSOCIATIONS
/**
* @OneToOne(targetEntity="Schedule", inversedBy="session")
* @JoinColumn(name="schId", referencedColumnName="id")
*/
protected $schedule;
/**
* @OneToOne(targetEntity="SnSoapeNotes", mappedBy="session")
* @JoinColumn(name="id", referencedColumnName="snId")
*/
protected $soapeNote;
/**
* @ManyToOne(targetEntity="Students")
* @JoinColumn(name="stdId", referencedColumnName="id")
*/
protected $student;
/**
* @ManyToOne(targetEntity="Personnel", inversedBy="sessions")
* @JoinColumn(name="trainerPsnId", referencedColumnName="id")
*/
protected $trainer;
// Getters and Setters
public function getId()
{
return $this->id;
}
public function getSchId()
{
return $this->schId;
}
public function setSchId($schId)
{
$this->schId = $schId;
}
public function getStdId()
{
return $this->stdId;
}
public function setStdId($stdId)
{
$this->stdId = $stdId;
}
public function getTrainerPsnId()
{
return $this->trainerPsnId;
}
public function setTrainerPsnId($trainerPsnId)
{
$this->stdId = $trainerPsnId;
}
public function getIsLegacy()
{
return $this->isLegacy;
}
public function setIsLegacy($isLegacy)
{
$this->isLegacy = $isLegacy;
}
public function getCharge()
{
return $this->charge;
}
public function setCharge($charge)
{
$this->charge = $charge;
}
public function getTrainerPay()
{
return $this->trainerPay;
}
public function setTrainerPay($trainerPay)
{
$this->trainerPay = $trainerPay;
}
public function getModeId()
{
return $this->modeId;
}
public function setModeId($modeId)
{
$this->modeId = $modeId;
}
public function getNotes()
{
return $this->notes;
}
public function setNotes($notes)
{
$this->notes = $notes;
}
public function getTwitterNote()
{
return $this->twitterNote;
}
public function setTwitterNote($twitterNote)
{
$this->twitterNote = $twitterNote;
}
// Foreign Data
public function getSchedule()
{
return $this->schedule;
}
public function getStudent()
{
return $this->student;
}
public function getTrainer()
{
return $this->trainer;
}
public function getSoapeNote()
{
return $this->soapeNote;
}
}
SnSoapeNotes:
namespace Entities;
use Doctrine\Mapping as ORM;
/**
* SnSoapeNotes
*
* @Table(name="SnSoapeNotes")
* @Entity(repositoryClass="Repositories\SnSoapeNotes")
*/
class SnSoapeNotes
{
/**
* @var integer Id
*
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var integer $mental
*
* @Column(name="mental", type="integer", nullable=false)
*/
private $mental;
/**
* @var integer $physical
*
* @Column(name="physical", type="integer", nullable=false)
*/
private $physical;
/**
* @var text $subjective
*
* @Column(name="subjective", type="text", nullable=false)
*/
private $subjective;
/**
* @var text $objective
*
* @Column(name="objective", type="text", nullable=false)
*/
private $objective;
/**
* @var text $plan
*
* @Column(name="plan", type="text", nullable=false)
*/
private $plan;
/**
* @var text $action
*
* @Column(name="action", type="text", nullable=false)
*/
private $action;
/**
* @var text $education
*
* @Column(name="education", type="text", nullable=false)
*/
private $education;
/**
* @var text $warning
*
* @Column(name="warning", type="text", nullable=true)
*/
private $warning;
/**
* @var text $incident
*
* @Column(name="incident", type="text", nullable=true)
*/
private $incident;
/**
* @var text $technical
*
* @Column(name="technical", type="text", nullable=true)
*/
private $technical;
// ASSOCIATIONS
/**
* @Var Sessions $sessions
*
* @Column(name="snId", type="integer", nullable=false)
* @OneToOne(targetEntity="Sessions", inversedBy="soapeNote")
* @JoinColumn(name="snId", referencedColumnName="id")
*/
protected $sessions;
// Getters and Setters
public function getSnId()
{
return $this->snId;
}
public function setSnId($snId)
{
$this->snId = $snId;
}
public function getMental()
{
return $this->mental;
}
public function setMental($mental)
{
$this->mental = $mental;
}
public function getPhysical()
{
return $this->physical;
}
public function setPhysical($physical)
{
$this->physical = $physical;
}
public function getSubjective()
{
return $this->subjective;
}
public function setSubjective($subjective)
{
$this->subjective = $subjective;
}
public function getObjective()
{
return $this->objective;
}
public function setObjective($objective)
{
$this->objective = $objective;
}
public function getPlan()
{
return $this->plan;
}
public function setPlan($plan)
{
$this->plan = $plan;
}
public function getAction()
{
return $this->action;
}
public function setAction($action)
{
$this->action = $action;
}
public function getEducation()
{
return $this->education;
}
public function setEducation($education)
{
$this->education = $education;
}
public function getWarning()
{
return $this->warning;
}
public function setWarning($warning)
{
$this->warning = $warning;
}
public function getIncident()
{
return $this->incident;
}
public function setIncident($incident)
{
$this->incident = $incident;
}
public function getTechnical()
{
return $this->technical;
}
public function setTechnical($technical)
{
$this->technical = $technical;
}
public function getSession()
{
return $this->session;
}
// A quick way to make sure the soape note has been completed.
// Note that objective is left out here because it can be
// filled out beforehand
public function getIsComplete()
{
return !empty($this->subjective)
&& !empty($this->action)
&& !empty($this->plan)
&& !empty($this->education);
}
}
當調用$ EM-> getRepository('\實體塞申斯) - > findOneBy( 'ID'),一切工作正常 - 我得到會議及其隨附的SOAPE筆記。其他關聯表的數據同上。
但現在我正在嘗試編寫一個自定義存儲庫,以便在此會話之前獲取備註。功能如下:
<?php
namespace Repositories;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\DBAL\Types\Type;
/**
* Sessions
*/
class Sessions extends EntityRepository
{
public function getPastSoapeNotes($params) {
$studentId = $params['studentId'];
$latestSession = $params['snDatetime'] ?: date('Y-m-d H:i');
$qb = $this->_em->createQueryBuilder();
$qb->select('n.subjective, n.objective, n.plan, n.action, n.education')
->from('Entities\Sessions', 'sn')
->innerJoin('sn.Entities\SnSoapeNotes', 'n');
return $qb->getQuery()->getResult();
}
}
當我打電話,我得到了以下錯誤:
我已經使用「的mappedBy」和「inersedBy」註釋在每一個可能的組合也試過,但無濟於事;學說似乎無法找到聯繫。至於發生了什麼,我完全喪失了信心。
您的會話實體在哪裏定義? – 2012-08-10 12:21:59