gac*_*rux 1 php cakephp associations
我有一对多关联,其中Thing可以有许多状态定义如下:
状态模型:
class Status extends AppModel
{
var $name = 'Status';
var $belongsTo = array(
'Thing' => array(
'className' => 'Thing',
'foreignKey' => 'thing_id',
);
}
Run Code Online (Sandbox Code Playgroud)
事物模型:
class Thing extends AppModel
{
var $name = 'Thing';
var $belongsTo = array(
// other associations
);
var $hasMany = array(
'Status' => array(
'className' => 'Status',
'foreignKey' => 'thing_id',
'dependent' => false,
'order' => 'datetime DESC',
'limit' => '10',
),
// other associations
);
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,但我希望Thing使用不同的ID连接到Status.例如Thing会对其所有其他关联使用'id',但使用'thing_status_id'作为Status关联.
我该怎么做才能做到最好?
小智 7
'foreignKey' => false而'conditions' => 'Thing.status_id = Status.thing_id'对关联选项可以找出你问什么.但我同意使用转换表进行habtm关系.
| 归档时间: |
|
| 查看次数: |
2255 次 |
| 最近记录: |