From 470fd797b683f7fb44e690bedf47a95fd6bf1957 Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Tue, 1 Apr 2014 14:17:19 -0500 Subject: [PATCH] Add unset() support to model and ::reset() to instrumented list --- include/class.orm.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/class.orm.php b/include/class.orm.php index b5541941d..98aa2371b 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -57,6 +57,9 @@ class VerySimpleModel { return array_key_exists($field, $this->ht) || isset(static::$meta['joins'][$field]); } + function __unset($field) { + unset($this->ht[$field]); + } function set($field, $value) { // Update of foreign-key by assignment to model instance @@ -354,7 +357,7 @@ class QuerySet implements IteratorAggregate, ArrayAccess { } function __toString() { - return (string)$this->getQuery(); + return (string) $this->getQuery(); } function getQuery($options=array()) { @@ -382,6 +385,7 @@ class ModelInstanceIterator implements Iterator, ArrayAccess { var $queryset; function __construct($queryset=false) { + $this->queryset = $queryset; if ($queryset) { $this->model = $queryset->model; $this->resource = $queryset->getQuery(); @@ -492,6 +496,13 @@ class InstrumentedList extends ModelInstanceIterator { $object->delete(); } + function update(array $what) { + return $this->queryset->update($what); + } + function reset() { + $this->cache = array(); + } + function offsetUnset($a) { $this->fillTo($a); $this->cache[$a]->delete(); -- GitLab