我有两个表到第三个表之间的关系,有额外的行,就像这个问题一样
/** @Entity
*/
class Illness {
/** @Id @GeneratedValue @Column(type="integer") */
private $illness_id;
/** @Column(type="string") */
private $name;
/** @OneToMany(targetEntity="Illness_Symptom_Association", mappedBy="Illness") */
private $symptAssoc;
public function __construct()
{
$this->symptAssoc = new \Doctrine\Common\Collections\ArrayCollection();
}
public function setName($val)
{
$this->name = $val;
}
public function getName()
{
return $this->name;
}
public function getSymptAssoc()
{
return $this->symptAssoc;
}
}
使用第三个参数连接表(类似于优先级)
/**
* @Entity
*/
class Illness_Symptom_Association {
protected $illness_id;
/**
* @Id()
* @ManyToOne(targetEntity="Illness", inversedBy="symptAssoc")
* @JoinColumn(name="illness_id", referencedColumnName="illness_id", nullable=false)
*/
protected $illness;
/**
* @Id()
* @ManyToOne(targetEntity="Symptom", inversedBy="symptAssoc")
* @JoinColumn(name="symptom_id", referencedColumnName="symptom_id")
* */
protected $symptom;
/** @Column(type="integer") */
protected $s;
public function setIllness(Illness $illness)
{
$this->illness = $illness;
}
/**
*
* @return Illness
*/
public function getIllness()
{
return $this->illness;
}
public function setSymptom(Symptom $sympt)
{
return $this->symptom = $sympt;
}
public function getSymptom()
{
return $this->symptom;
}
public function setS($s)
{
$this->s = $s;
}
public function getS()
{
return $this->s;
}
}
最后一个有症状的实体:
/**
* @Entity
*/
class Symptom {
/** @Id @GeneratedValue @Column(type="integer") */
protected $symptom_id;
/** @Column(type="string", unique=true) */
protected $name;
/** @OneToMany(targetEntity="Illness_Symptom_Association", mappedBy="symptom") */
protected $symptAssoc;
public function setName($name)
{
$this->name = $name;
}
public function getName($name)
{
return $this->name;
}
}
但
$illness = $em->getRepository('Entity\Illness')->find($id);
$illness->getSymptAssoc();
返回PersistentCollection对象。
如何从连接表中获取带有s参数的症状列表?