开发者

Friendship model in CakePHP

开发者 https://www.devze.com 2023-02-19 19:51 出处:网络
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_

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

精彩评论

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