diff --git a/include/class.orm.php b/include/class.orm.php index 46a6d6b83737d4908efa10dd678e673180440bc5..16bdad71130867cf7a31a4c61e2921f38a59e2bd 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -435,10 +435,6 @@ class ModelInstanceIterator implements Iterator, ArrayAccess { return $this->cache; } - function objects() { - return clone $this->queryset; - } - // Iterator interface function rewind() { $this->position = 0; @@ -507,23 +503,43 @@ class InstrumentedList extends ModelInstanceIterator { $this->resource = null; } - function add($object) { + function add($object, $at=false) { if (!$object || !$object instanceof $this->model) throw new Exception('Attempting to add invalid object to list'); - $object->{$this->key} = $this->id; + $object->set($this->key, $this->id); $object->save(); - $this->list[] = $object; + + if ($at !== false) + $this->cache[$at] = $object; + else + $this->cache[] = $object; } function remove($object) { $object->delete(); } + function reset() { + $this->cache = array(); + } + + // QuerySet delegates + function count() { + return $this->queryset->count(); + } + function exists() { + return $this->queryset->exists(); + } + function expunge() { + return $this->queryset->delete(); + } function update(array $what) { return $this->queryset->update($what); } - function reset() { - $this->cache = array(); + + // Fetch a new QuerySet + function objects() { + return clone $this->queryset; } function offsetUnset($a) { @@ -533,7 +549,7 @@ class InstrumentedList extends ModelInstanceIterator { function offsetSet($a, $b) { $this->fillTo($a); $this->cache[$a]->delete(); - $this->add($b); + $this->add($b, $a); } }