我有一個疑問,林在Ruby on Rails的網站製作一個朋友的平臺2和表之間的關係2;我有一個名爲用戶表,稱爲表朋友管理用戶之間的友誼。在朋友我有2個字段,* user_id1 *和* user_id2 *。這是款我做的關係:問題與紅寶石在同一列on Rails的
class User < ActiveRecord::Base has_many :friends end
class Friend < ActiveRecord::Base belongs_to :user, :foreign_key => "user_id1" belongs_to :user, :foreign_key => "user_id2" end
這是處理這種情況的好辦法?另一個想法是創建另一個模型,指向數據庫中的同一個表,userAux,並將其用於關係。你認爲最好的是什麼?你有更好的主意嗎?
在此先感謝。