Skip to content
Snippets Groups Projects
Commit 40e1ac2e authored by Jared Hancock's avatar Jared Hancock
Browse files

orm: Add ::count() and ::expunge() to InstrumentedList

parent 5ef66b87
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment