public function create($query, array $options = array())
{
return $this->_filter(__METHOD__, compact('query', 'options'), function ($self, $params) {
$query = $params['query'];
$model = $entity = $object = $id = null;
if (is_object($query)) {
$object = $query;
$model = $query->model();
$params = $query->export($self);
$entity =& $query->entity();
$query = $self->renderCommand('create', $params, $query);
} else {
$query = String::insert($query, $self->value($params['options']));
}
if (!$self->invokeMethod('_execute', array($query))) {
return false;
}
if ($entity) {
if ($model && !$model::key($entity)) {
$id = $self->invokeMethod('_insertId', array($object));
}
$entity->sync($id);
}
return true;
});
}