我有两个对象Schedule
和LocationPage
。对象Schedule
与$has_one
的关联LocationPage
:
class Schedule extends DataObject {
private static $db = array(
'Date' => 'Date',
);
private static $has_one = array(
'Location' => 'LocationPage',
);
}
和
class LocationPage extends Page {
private static $db = [
'Heading' => 'HTMLVarchar(250)',
'SubHeading' => 'Varchar(250)'
];
}
当我尝试按关系字段Title
排序时,它会给我一个错误。这是排序代码:
Schedule::get()->sort(['Location.Title' => 'ASC']);
以下是调用上述代码时出现的排序错误:
[用户错误]未捕获SS_DatabaseException:无法运行查询:SELECT DISTINCT" Schedule"。" ClassName"," Schedule"。&#34 ; LastEdited"," Schedule"。" Created"," Schedule"。" Date"," Schedule" 。" LocationID"," Schedule"。" ID",CASE WHEN" Schedule"。" ClassName"那不是空的"安排"。" ClassName" ELSE' Schedule'结束AS" RecordClassName"," LocationPage"。" Title" AS" _SortColumn0"来自"附表" LEFT JOIN" LocationPage" ON" LocationPage"。" ID" =" Schedule"。" LocationID" INNER JOIN" Page" ON" LocationPage"。" ID" =" Page"。" ID" INNER JOIN" SiteTree" ON" LocationPage"。" ID" =" SiteTree"。" ID" ORDER BY" _SortColumn0" ASC未知专栏' LocationPage.Title'在'字段列表'
是什么导致了这个问题?
答案 0 :(得分:0)
此问题的解决方法是使has_one关系指向SiteTree而不是LocationPage。