【问题标题】:Select multiple columns from inner join in Silverstripe 3.1从 Silverstripe 3.1 的内部连接中选择多列
【发布时间】:2016-07-14 15:33:07
【问题描述】:

在 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 表中选择列? 任何帮助将不胜感激。谢谢

【问题讨论】:

    标签: php mysql sql silverstripe


    【解决方案1】:

    我找到了手动方式:

    $list = DB::query('SELECT * FROM "CalendarDateTime" INNER JOIN "CalendarEvent" ON "EventID" = "CalendarEvent"."ID" INNER JOIN "SiteTree" ON "SiteTree"."ID" = "CalendarEvent"."ID" WHERE "Recursion" != 1');
    

    欢迎任何其他解决方案。

    【讨论】:

      猜你喜欢
      • 2019-08-21
      • 1970-01-01
      • 2020-10-08
      • 2012-06-10
      • 1970-01-01
      • 2016-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多