Partical Cache and sortColumn update #35

joernroeder opened this Issue May 24, 2013 · 5 comments


2 participants

I just saw that GridFieldSortableRows uses plain SQL to update the sortColumn which makes it a bit difficult to use it with the partical cache and aggregates like <% cached 'sortablelist', List(SortableObject).max(LastEdited) %>.
As the sortColumn doesn't reflect a relation lastEdited should be updated.
What do you think?


UndefinedOffset commented May 24, 2013

I could do this on has_many relationships and it did when I was using DataObject::write(). But for efficiency I switched to plain sql never thought to update the LastEdit date but it makes complete sense especially given the case your suggesting.

Hey cool! thx for the quick improvement!

After updating to the latest version I got an error, related to the lastEdited-field on some of my DataObjects.
I figured out that some of the dataObjects are splited between multiple tables, for example a sub-class of Page with some extra database fields.
All page fields are stored within the Sitetree table but the custom fields including the sortableField are stored in another (sub class)-table. Therefore the LastEdited-field doesn't exist and the following error occurs:

ERROR [User Error]: Couldn't run query: UPDATE "Section" SET "Priority" = 1,"LastEdited"='2013-05-25 16:13:35'WHERE "ID" = 23 Unknown column 'LastEdited' in 'field list'IN POST /admin/sections/Section/EditForm/field/SectionLine 592 in /framework/model/MySQLDatabase.phpSource====== 583: } 584: 585: public function databaseError($msg, $errorLevel = E_USER_ERROR) { 586: // try to extract and format query 587: if(preg_match('/Couldn't run query: ([^|])|\s(.)/', $msg, $matches)) { 588: $formatter = new SQLFormatter(); 589: $msg = "Couldn't run query: \n" . $formatter->formatPlain($matches[1]) . "\n\n" . $matches[2]; 590: } 591: * 592: user_error($msg, $errorLevel); 593: } 594: 595: /* 596: * Return a boolean type-formatted string 597: * 598: * @param array $values Contains a tokenised list of info about this data typeTrace=====user_error(Couldn't run query: UPDATE "Section" SET "Priority" = 1,"LastEdited"='2013-05-25 16:13:35'WHERE "ID" = 23 Unknown column 'LastEdited' in 'field list',256)MySQLDatabase.php:592MySQLDatabase->databaseError(Couldn't run query: UPDATE "Section" SET "Priority" = 1,"LastEdited"='2013-05-25 16:13:35' WHERE "ID" = 23 | Unknown column 'LastEdited' in 'field list',256)MySQLDatabase.php:144MySQLDatabase->query(UPDATE "Section" SET "Priority" = 1,"LastEdited"='2013-05-25 16:13:35' WHERE "ID" = 23,256)DB.php:200DB::query(UPDATE "Section" SET "Priority" = 1,"LastEdited"='2013-05-25 16:13:35' WHERE "ID" = 23)GridFieldSortableRows.php:332GridFieldSortableRows->saveGridRowSort(GridField,Array)GridFieldSortableRows.php:245GridFieldSortableRows->handleAction(GridField,savegridrowsort,Array,Array)GridField.php:674GridField->handleAlterAction(saveGridRowSort,Array,Array)GridField.php:636GridField->gridFieldAlterAction(Array,Form,SS_HTTPRequest)GridField.php:108GridField->index(SS_HTTPRequest)RequestHandler.php:278RequestHandler->handleAction(SS_HTTPRequest,index)RequestHandler.php:190RequestHandler->handleRequest(SS_HTTPRequest,DataModel)GridField.php:749

My tables look like this:

ID  |  ClassName  |  Created  |  LastEdited

ID  |  Priority  |  Some  |  extra  |  fields

hope that helps ;)


UndefinedOffset commented May 25, 2013

Right... because I forgot to take into account the sort column can be on a decedent of the base object. I'll do up a change to address this.


UndefinedOffset commented May 25, 2013

Should be good to go now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment