From 1e88be0e213062322455e0a82524a2b419aad7d3 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 9 Oct 2015 00:29:04 +1100 Subject: [PATCH] Enable caching related models --- modules/orm/classes/Kohana/ORM.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/modules/orm/classes/Kohana/ORM.php b/modules/orm/classes/Kohana/ORM.php index 54f3a86..341b5b0 100644 --- a/modules/orm/classes/Kohana/ORM.php +++ b/modules/orm/classes/Kohana/ORM.php @@ -345,6 +345,7 @@ class Kohana_ORM extends Model implements serializable { } $defaults = array(); + $defaults['cached'] = FALSE; foreach ($this->_belongs_to as $alias => $details) { @@ -650,6 +651,10 @@ class Kohana_ORM extends Model implements serializable { // See: http://mysql.localhost.net.ar/doc/refman/5.1/en/server-session-variables.html#sysvar_sql_auto_is_null if ($val !== NULL) { + // Enable caching query + if ($this->_belongs_to[$column]['cached']) + $model->cached(); + $model->where($col, '=', $val)->find(); } @@ -677,6 +682,10 @@ class Kohana_ORM extends Model implements serializable { } } + // Enable caching query + if ($this->_has_one[$column]['cached']) + $model->cached(); + $model->where($col, '=', $val)->find(); return $this->_related[$column] = $model; @@ -709,6 +718,10 @@ class Kohana_ORM extends Model implements serializable { $val = $this->_object[$this->_has_many[$column]['far_key']]; } + // Enable caching query + if ($this->_has_many[$column]['cached']) + $model->cached(); + return $model->where($col, '=', $val); } else @@ -729,6 +742,10 @@ class Kohana_ORM extends Model implements serializable { $model = $model->where($col, '=', $val); } + // Enable caching query + if ($this->_has_many[$column]['cached']) + $model->cached(); + return $model; } }