多余的许多自我引用多余的列 [英] Doctrine many to many self referencing with extra columns

查看:162
本文介绍了多余的许多自我引用多余的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与教义&我有一些问题在多对多的自我引用,其中有一些额外的领域。
可以描述我的情况:
我有一个名为Drug的表,药物可能会相互冲突&这种冲突可能会出现在某些条件&可能有一些解决方案。



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



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

  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药物
*
* @ ORM\ManyToOne(targetEntity =Drug,inversedBy =drugConfilict1s)
* @ ORM\JoinColumn(name =drug1_id,referencedColumnName =id)
* /
private $ drug1;

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

感谢您的答案:)

解决方案

您提供的解决方案是正确的。也许如果你能描述实际冲突的性质,他们可能会更好的数据模型或数据处理。


i'm working with doctrine & i have some problem in many-to-many self referencing which has some extra fields. lets describe my scenario : i have a table named Drug , drugs can have conflicts with each other & this conflicts may appear under some conditions & may have some solutions.

i've read doctrine documents about many-to-many relations & it's mentioned that it's not good for JoinTable to have some extra fileds. so what's the best solution for this problem?

here is my solution, but i'm not sure that this is the best one or not.

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;
}

thanks for your answers :)

解决方案

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.

这篇关于多余的许多自我引用多余的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆