我有一个相当奇怪的问题。我在 Zend Framework 1.11 下使用 Doctrine 2。我有一个名为“Sessions”的数据库,它是针对学生的培训课程。每个会话都有一个关联的注释,称为 SOAPE 注释。编辑:我现在包括两个有问题的实体。
会议:
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;
}
}
SnSoape注意事项:
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('Entities\Sessions')->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();
}
}
当我调用它时,我收到以下错误:
[Semantical Error] line 0, col 126 near 'n': Error: Class Entities\Sessions has no association named Entities\SnSoapeNotes
我还尝试在每种可能的组合中使用“mappedBy”和“inersedBy”注释,但无济于事;教义似乎找不到关联。我完全不知道发生了什么。