不知道如何在 CakePHP 3.2 上使用 RightJoin 检索信息
Do not know how to retrieve information with RightJoin on CakePHP 3.2
- CakePHP 版本:3.2
- 平台和目标:Wamp、MySQq、GoogleChrome
我做了什么
右连接在一个控制器中的两个表之间。我正在尝试检索信息,但我做不到
$query = $this->Schedules->find('all')
->rightJoin(['Sessions'=> 'sessions'], ['Sessions.id is not null'])
->select(['Sessions.specialist_id'])
->where(['Sessions.id ='=>$session])
foreach ($query as $sp) {
if(!empty($sp)){
$specialist=$sp->Sessions->specialist_id;
预期行为
获取专家id
实际行为
我无法获取专家 ID
更多信息
1 我已经尝试过 $specialist=$sp->specialist_id;
但没有任何反应
2 debug ($sp);die();
这就是我得到的
object(App\Model\Entity\Schedule) {
'Sessions' => [
'specialist_id' => 'a7f6d5b2-b0f3-4a55-b6ce-41d393e80d12'
],
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Schedules'
}
specialist_id
属于Sessions
,所以需要通过那个键访问,即
$sp->Sessions['specialist_id']
或
$sp['Sessions']['specialist_id']
甚至
$sp->get('Sessions')['specialist_id']
... ooooooor,一旦 that feature 进入核心
$sp->get('Sessions.specialist_id')
这是相当基本的内容,但也许文档可以从有关如何访问嵌套数据的示例中获益,包括对象和数组的混合。
Cookbook > Database Access & ORM > Entities > Accessing Entity Data
附带说明一下,AFAICT $sp
永远不应为空,要么有结果,要么没有。
- CakePHP 版本:3.2
- 平台和目标:Wamp、MySQq、GoogleChrome
我做了什么
右连接在一个控制器中的两个表之间。我正在尝试检索信息,但我做不到
$query = $this->Schedules->find('all')
->rightJoin(['Sessions'=> 'sessions'], ['Sessions.id is not null'])
->select(['Sessions.specialist_id'])
->where(['Sessions.id ='=>$session])
foreach ($query as $sp) {
if(!empty($sp)){
$specialist=$sp->Sessions->specialist_id;
预期行为
获取专家id
实际行为
我无法获取专家 ID
更多信息
1 我已经尝试过 $specialist=$sp->specialist_id;
但没有任何反应
2 debug ($sp);die();
这就是我得到的
object(App\Model\Entity\Schedule) {
'Sessions' => [
'specialist_id' => 'a7f6d5b2-b0f3-4a55-b6ce-41d393e80d12'
],
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Schedules'
}
specialist_id
属于Sessions
,所以需要通过那个键访问,即
$sp->Sessions['specialist_id']
或
$sp['Sessions']['specialist_id']
甚至
$sp->get('Sessions')['specialist_id']
... ooooooor,一旦 that feature 进入核心
$sp->get('Sessions.specialist_id')
这是相当基本的内容,但也许文档可以从有关如何访问嵌套数据的示例中获益,包括对象和数组的混合。
Cookbook > Database Access & ORM > Entities > Accessing Entity Data
附带说明一下,AFAICT $sp
永远不应为空,要么有结果,要么没有。