如果我正在使用 cake 3 处理搜索表单,并且我已使用此行根据插入的 ID 到 url 获取结果
$data = $this->CustodyKeys->HoldersKeys->find('all',array('conditions'=>array('HoldersKeys.id'=> $this->request->query['holders_keys_id'])));
现在,我需要获取与 HoldersKeys 表关联的相关数据,但我不知道如何使用 contains 来使用之前的代码获取关联数据?
任何人都可以帮忙吗?
最佳答案
将 contain()
添加到您的查询中。
https://book.cakephp.org/3.0/en/orm/query-builder.html#loading-associations
<?php
$data = $this->CustodyKeys->HoldersKeys
->find(
'all',
['conditions' => ['HoldersKeys.id' => $this->request->query['holders_keys_id']]]
)
->contain('TableName');
关于php - 使用 cake3 php 获取搜索表单结果的 get 请求获取关联数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44111547/