[英]Select multiple columns from inner join in Silverstripe 3.1
在Silverstripe 3.1的事件日歷模塊中,我向CalendarEvent添加了一些額外的字段。 我想在我的模板中使用這些,但是從我的研究中我看到事件被導出為CalendarDateTime,所以我不能使用我的附加字段。
我發現在getStandardEvents函數中,有一個內部連接,我認為是導致問題,但我無法弄清楚從CalendarEvent加入列
$list = DataList::create('CalendarDateTime')
->filter(array(
'EventID' => [139, 140, 141, 143]
))
->innerJoin('CalendarEvent', "EventID = \"{CalendarEvent}\".\"ID\"")
->innerJoin("SiteTree", "\"SiteTree\".\"ID\" = \"{CalendarEvent}\".\"ID\"")
->where("Recursion != 1");
注意:在我的代碼中,我將一些列作為變量,因此我將它們寫為正在進行的值。 這是原始代碼:
$list = DataList::create($datetimeClass)
->filter(array(
$relation => $ids
))
->innerJoin($eventClass, "$relation = \"{$eventClass}\".\"ID\"")
->innerJoin("SiteTree", "\"SiteTree\".\"ID\" = \"{$eventClass}\".\"ID\"")
->where("Recursion != 1");
我試圖在DataList :: create()中添加'CalendarEvent'作為第二個參數,但沒有結果。 我有相同的輸出。
那么我如何從CalendarDateTime和CalendarEvent表中選擇列? 任何幫助將不勝感激。謝謝
我找到了一種手動方式:
$list = DB::query('SELECT * FROM "CalendarDateTime" INNER JOIN "CalendarEvent" ON "EventID" = "CalendarEvent"."ID" INNER JOIN "SiteTree" ON "SiteTree"."ID" = "CalendarEvent"."ID" WHERE "Recursion" != 1');
歡迎任何其他解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.