0

我正在使用学说,我在多对多自引用中遇到了一些问题,它有一些额外的字段。让我们描述一下我的场景:我有一个名为 Drug 的表,药物之间可能存在冲突,这种冲突可能在某些情况下出现,并且可能有一些解决方案。

我已经阅读了关于多对多关系的原则文档,并且提到了 JoinTable 有一些额外的文件是不好的。那么这个问题的最佳解决方案是什么?

这是我的解决方案,但我不确定这是否是最好的解决方案。

class Drug{
..
/**
 * @var DrugConfilict
 * 
 * @ORM\OneToMany(targetEntity="DrugConfilict", mappedBy="drug1")
 */
private $drugConfilict1s;

/**
 * @var DrugConfilict
 * 
 * @ORM\OneToMany(targetEntity="DrugConfilict", mappedBy="drug2")
 */
private $drugConfilict2s;
}

class DrugConfilict
{
/**
 * @var string
 *
 * @ORM\Column(name="confilict_conditions", type="text", nullable=true)
 */
private $confilictConditions;

/**
 * @var string
 *
 * @ORM\Column(name="what_should_do", type="text", nullable=true)
 */
private $whatShouldDo;

/**
 * @var Drug
 * 
 * @ORM\ManyToOne(targetEntity="Drug", inversedBy="drugConfilict1s")
 * @ORM\JoinColumn(name="drug1_id", referencedColumnName="id")
 */
private $drug1;

/**
 * @var Drug
 * 
 * @ORM\ManyToOne(targetEntity="Drug", inversedBy="drugConfilict2s")
 * @ORM\JoinColumn(name="drug2_id", referencedColumnName="id")
 */
private $drug2;
}

谢谢你的回答:)

4

1 回答 1

0

The solution you provided is correct. Perhaps if you can describe the nature of the actual conflict their might be a better data model or data handling for it.

于 2013-08-14T16:50:02.120 回答