我在 cake 3.2 中做了模型关联
在这里,我已经为同一张表的一个 id 完成了它。
我试图为其他人做,但它根本不起作用
下面是流程。
我得到的这个输出
{
"id": 1,
"publisher_id": 133,
"user_id": 118,
"Publisher": {
"id": 133,
"name": "Sradha sradha"
}
在这里我也想绑定用户ID,它属于同一个用户表
输出应该是这样的(我想在下面得到这样的)
{
"id": 1,
"publisher_id": 133,
"user_id": 118,
"Publisher": {
"id": 133,
"name": "Sradha sradha"
}
"Users": {
"id": 118,
"name": "Sradha anjo"
}
这里 publisher_id 和 user_id 都属于同一个用户表。
$this->AdminRevenues->belongsTo('Users', [
'className' => 'Users',
'foreignKey' => 'user_id',
'propertyName' => 'Users']);
$this->AdminRevenues->belongsTo('Users', [
'className' => 'Publisher',
'foreignKey' => 'publisher_id',
'propertyName' => 'Publisher']);
$totalAdminRevenue = $this->AdminRevenues->find('all')
->contain([
'Users' => ['queryBuilder' => function ($q) {
return $q->select(['id', 'name']);
}]])
->toArray();
请提出建议,任何建议将不胜感激。