Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partical Cache and sortColumn update #35

Closed
joernroeder opened this issue May 24, 2013 · 5 comments
Closed

Partical Cache and sortColumn update #35

joernroeder opened this issue May 24, 2013 · 5 comments

Comments

@joernroeder
Copy link

Hey,
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
Copy link
Owner

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.

@joernroeder
Copy link
Author

Hey cool! thx for the quick improvement!

@joernroeder
Copy link
Author

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:

TranslatableDataObject
-------------------------------------------
ID  |  ClassName  |  Created  |  LastEdited
-------------------------------------------

Section
---------------------------------------------
ID  |  Priority  |  Some  |  extra  |  fields
---------------------------------------------

hope that helps ;)

@UndefinedOffset
Copy link
Owner

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
Copy link
Owner

Should be good to go now

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

No branches or pull requests

2 participants