From 541c8a8904fb8fb113b0470e55309c15bcde7008 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 21 Feb 2008 02:23:39 +0000 Subject: [PATCH] Merged revisions 49946 via svnmerge from svn://svn.silverstripe.com/silverstripe/modules/sapphire/branches/2.2.0-mesq ........ r49946 | ischommer | 2008-02-21 15:21:48 +1300 (Thu, 21 Feb 2008) | 1 line fixed caching in getManyManyComponents (see r43848) ........ git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@49940 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/DataObject.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/model/DataObject.php b/core/model/DataObject.php index 565d389f8..30981399d 100644 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -862,7 +862,10 @@ class DataObject extends ViewableData implements DataObjectInterface { * @todo Implement query-params */ public function getManyManyComponents($componentName, $filter = "", $sort = "", $join = "", $limit = "") { - if(isset($this->components[$componentName])) return $this->components[$componentName]; + $sum = md5("{$filter}_{$sort}_{$join}_{$limit}_{$having}"); + if(isset($this->componentCache[$componentName . '_' . $sum]) && false != $this->componentCache[$componentName . '_' . $sum]) { + return $this->componentCache[$componentName . '_' . $sum]; + } list($parentClass, $componentClass, $parentField, $componentField, $table) = $this->many_many($componentName); @@ -896,7 +899,12 @@ class DataObject extends ViewableData implements DataObjectInterface { $result = new ComponentSet(); } $result->setComponentInfo("many-to-many", $this, $parentClass, $table, $componentClass); - $this->components[$componentName] = $result; + + // If this record isn't in the database, then we want to hold onto this specific ComponentSet, + // because it's the only copy of the data that we have. + if(!$this->isInDB()) { + $this->setComponent($componentName . '_' . $sum, $result); + } return $result; }