【发布时间】:2016-12-07 10:48:53
【问题描述】:
我有一个表名countries,countries与users有关系,users与MoneyTransferTransactions有关系
在MoneyTransferTransactions 视图中,我需要获取国家/地区名称。
我已经通过下面的代码加入了MoneyTransferTransactionsTable中的用户表
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
'joinType' => 'INNER'
]);
在用户表中,我还使用了如下代码的内连接
$this->belongsTo('Countries', [
'foreignKey' => 'country_id',
'joinType' => 'INNER'
]);
在 MoneyTransferTransactions 控制器中,我使用下面的代码来获取所有具有关联数据的数据。
$this->paginate = [
'contain' => ['Users','TransferOptions'],
'conditions'=> ['MoneyTransferTransactions.status'=>1],
'order' =>['MoneyTransferTransactions.id'=>'DESC']
];
我在 index.ctp 中使用了 var_dump,我从 users 表中获得了国家 ID,但没有从国家表中获得国家名称。如何从MoneyTransferTransactions>index.ctp 获取国家名称?
【问题讨论】:
-
你必须添加国家来包含
-
它给了我错误“MoneyTransferTransactions 与国家没有关联”
-
添加 Users.Countries 以包含并从中删除用户
标签: cakephp cakephp-3.0 cakephp-3.x