开发者

Friendship model in CakePHP

I have a "Friendship" table:

id | user_id_1 | user_id_2 | accepted

basically it references 2 users (where user_id_1 is the reques开发者_开发技巧ter) and contains an accepted flag (whether user_id_2 has accepted the request).

How do I set up the model in CakePHP so that it automatically appends the user information from my Users table?


Use the belongsTo relationship in your model: http://book.cakephp.org/view/1042/belongsTo

This might look something like:

class Friendship extends AppModel {
  var $name = 'Friendship';
  var $belongsTo = array(
    'user_id_1' => array(
      'className' => 'User',
      'foreignKey' => 'user_id'
    ),
    'user_id_2' => array(
      'className' => 'User',
      'foreignKey' => 'user_id'
    )
  );
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜