经过大量搜索,我发现:https ://github.com/UndefinedOffset/SortableGridField/blob/master/docs/ManyManyExample.md的用法示例。
但是,实现此代码会导致:
[用户错误] 无法运行查询:SELECT DISTINCT MAX("SortOrder") FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"." TwoColumnID" = '2') 字段列表中的列 'SortOrder' 不明确
我正在使用 SS3 并安装了 SortableGridField(尽管在运行 dev/build/?flush=all 时没有消息表明安装成功)。
关闭开发模式时,CMS 不会加载(“服务器错误”),但是启用开发模式后,我会收到上述 SQL 错误。无论如何,它似乎工作正常,我只需要找出引发此错误的原因。
更新
以下是此错误生成的堆栈跟踪的顶部(页面上有 2 个 [User Error] 蓝色标题):
[User Error] Couldn't run query: SELECT DISTINCT MAX("SortOrder") FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') Column 'SortOrder' in field list is ambiguous
Couldn't run query: SELECT DISTINCT MAX("SortOrder") FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') Column 'SortOrder' in field list is ambiguous
MySQLDatabase.php:580
MySQLDatabase->databaseError(Couldn't run query: SELECT DISTINCT MAX("SortOrder") FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') | Column 'SortOrder' in field list is ambiguous,256)
MySQLDatabase.php:132
MySQLDatabase->query(SELECT DISTINCT MAX("SortOrder") FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2'),256)
DB.php:200
DB::query(SELECT DISTINCT MAX("SortOrder") FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2'),256)
SQLQuery.php:949
SQLQuery->execute()
DataQuery.php:372
DataQuery->aggregate(MAX("SortOrder"))
DataQuery.php:338
DataQuery->max(SortOrder)
DataList.php:676
DataList->max(SortOrder)
GridFieldSortableRows.php:148
GridFieldSortableRows->fixSortColumn(GridField,ManyManyList)
GridFieldSortableRows.php:99
GridFieldSortableRows->getManipulatedData(GridField,ManyManyList)
GridField.php:215
GridField->getManipulatedList()
GridField.php:255
GridField->FieldHolder()
...
[User Error] Couldn't run query: SELECT DISTINCT count(DISTINCT "Sidebar"."ID") AS "0" FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') AND ("SortOrder"=0) Column 'SortOrder' in where clause is ambiguous
Couldn't run query: SELECT DISTINCT count(DISTINCT "Sidebar"."ID") AS "0" FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') AND ("SortOrder"=0) Column 'SortOrder' in where clause is ambiguous
MySQLDatabase.php:580
MySQLDatabase->databaseError(Couldn't run query: SELECT DISTINCT count(DISTINCT "Sidebar"."ID") AS "0" FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') AND ("SortOrder"=0) | Column 'SortOrder' in where clause is ambiguous,256)
MySQLDatabase.php:132
MySQLDatabase->query(SELECT DISTINCT count(DISTINCT "Sidebar"."ID") AS "0" FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') AND ("SortOrder"=0),256)
DB.php:200
DB::query(SELECT DISTINCT count(DISTINCT "Sidebar"."ID") AS "0" FROM "Sidebar" INNER JOIN "TwoColumn_Sidebars" ON "TwoColumn_Sidebars"."SidebarID" = "Sidebar"."ID" WHERE ("TwoColumn_Sidebars"."TwoColumnID" = '2') AND ("SortOrder"=0),256)
SQLQuery.php:949
SQLQuery->execute()
SQLQuery.php:1054
SQLQuery->count(DISTINCT "Sidebar"."ID")
DataQuery.php:329
DataQuery->count()
DataList.php:666
DataList->count()
GridFieldSortableRows.php:150
GridFieldSortableRows->fixSortColumn(GridField,ManyManyList)
GridFieldSortableRows.php:99
GridFieldSortableRows->getManipulatedData(GridField,ManyManyList)
GridField.php:215
GridField->getManipulatedList()
GridField.php:255
GridField->FieldHolder()
ViewableData.php:366
ViewableData->obj(FieldHolder,,,1)
...