我正在使用 CakePHP 框架来构建一个 Web 应用程序。我的问题的最简单形式是:
我有一个用户表和一个带有相应模型的消息表。消息从一个用户发送给另一个用户。因此,messages 表中包含 from_id 和 to_id 列,它们都引用了用户的 id。我可以使用 $belongsTo 将消息模型链接到用户模型,但我无法通过以相同方式使用 $hasMany 将用户模型与消息模型(反向)链接。
var $hasMany = array(
'From' => array(
'className' => 'Message',
'foreignKey' => 'from_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
),
'To' => array(
'className' => 'Message',
'foreignKey' => 'to_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
在这里可以做什么?有任何想法吗?谢谢你的帮助。