我正在使用kohana3。Kohana 3.1 ORM關係問題
表: 用戶ID的用戶名friend_id
user_relationships ID user_ID的friend_id
我試圖做到以下幾點:
假設,我有ID = 1 USER_TABLE。然後我想爲這個用戶獲取一個friend_id數組。假設它會是(2,3)。然後我想爲ID的用戶名=(2,3)
用戶模型:
protected $_has_many = array(
'userrelations' => array()
);
userrelationships型號:
protected $_belongs_to = array(
'user' => array(),
);
控制器:
$user = ORM::factory('user', 1);
$friends = $user->userrelations->find_all();
我只recive [「id」] => string(1)「1」[「user_id」] => string(1)「1」[「friend_id」] => string(1)「2」 我寫信得到我想要的東西?
用戶有很多朋友,用戶可以成爲很多其他用戶的朋友。它是否應該通過「HABTM」關係? – biakaveron 2011-06-08 18:26:34
你是對的,比卡凱龍 – Fenec 2011-06-09 09:13:00