function insert()
{
if (isset($this->document['_id'])) {
return $this->update();
}
if (isset($this->trigger['beforeinsert']) && \Base::instance()->call($this->trigger['beforeinsert'], [$this, ['_id' => $this->document['_id']]]) === FALSE) {
return $this->document;
}
$this->collection->insert($this->document);
$pkey = ['_id' => $this->document['_id']];
if (isset($this->trigger['afterinsert'])) {
\Base::instance()->call($this->trigger['afterinsert'], [$this, $pkey]);
}
$this->load($pkey);
return $this->document;
}