我正在使用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