我有一個用戶實體和一個關係實體。 (該關係的實體是確定社會關係的Facebook好友,Twitter的追隨者...等)映射到columnA **或** columnB與Doctrine
這裏是我的關係類來更好地理解它:
/**
* Describes a relationship between two users in the direction of user1 to user2. (i.e. user1 is 'friends' with user2)
* This relationship may be mutual
* @package AppBundle\Entity
*/
class Relationship {
protected $id;
protected $user1;
protected $user2;
protected $source;
protected $type;
protected $mutual;
/**
* @param string $source The source of the relationship information (facebook, twitter...etc.)
* @param string $type The type of relationship. (source specific) e.g. friends, follower
* @param int $user1 The user id
* @param int $user2 The user id
* @param bool $mutual If set to true than the reverse relationship is true (i.e. user2 is 'friends' with user1 as well)
* This may seem obvious for facebook friends but the twitter follower relationship is not always mutual
*/
function __construct($user1,$user2,$source,$type,$mutual)
{
$this->user1 = $user1;
$this->user2 = $user2;
$this->source = $source;
$this->type = $type;
$this->mutual = $mutual;
}
我有被映射用戶帶來的麻煩關係實體的實體。
用戶的特定實例可能是user1
或user2
在關係中。
我不能明確映射到關係的實體的user1
列,因爲它可能是user2
我試圖避免在關係表中重複項具有一個條目定義雙向(完成與$相互關係屬性)。
有沒有辦法在教義地圖這使得用戶將有機會獲得他們的關係(例如用戶 - > getRelationships),無論它們是否是user1
或user2
?