簡體   English   中英

不知道如何在CakePHP 3.2上使用RightJoin檢索信息

[英]Do not know how to retrieve information with RightJoin on CakePHP 3.2

  • CakePHP版本:3.2
  • 平台和目標:Wamp,MySQq,Google Chrome

我做了什么

在一個控制器中的兩個表之間右聯接。 我正在嘗試檢索信息,但無法

$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

實際行為

我無法獲得專家證件

更多信息

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']

...哦,一旦該功能成為核心

$sp->get('Sessions.specialist_id')

這是相當基礎的東西,但是文檔可能會受益於有關如何訪問嵌套數據的示例,其中包括對象和數組的混合。

食譜>數據庫訪問和ORM>實體>訪問實體數據

附帶說明一下,AFAICT $sp永遠不應為空,無論結果是沒有。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM