2015-04-03 44 views
0

我有一個用戶實體和一個關係實體。 (該關係的實體是確定社會關係的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; 

    } 

我有被映射用戶帶來的麻煩關係實體的實體。

用戶的特定實例可能是user1user2在關係中。

我不能明確映射到關係的實體的user1列,因爲它可能是user2

我試圖避免在關係表中重複項具有一個條目定義雙向(完成與$相互關係屬性)。

有沒有辦法在教義地圖這使得用戶將有機會獲得他們的關係(例如用戶 - > getRelationships),無論它們是否是user1user2

回答

1

老實說:「我不知道」 :(

但是我在這裏回答的理由是帶來了點。用戶1和用戶都是用戶的實例。所以,這裏的問題是,用戶實體是兩個不同的角色,一個用戶引用另一個用戶,我的意思是一個用戶的主鍵是用戶的外鍵(自引用),我個人在創建社交應用時面臨這個問題,一個用戶是另一個用戶的朋友。用戶在同一時間,用戶的朋友。我通過複製該行解決了這個問題的朋友,你不想。順便說一句,我還等着任何麪糊的解決方案。祝您好運