Commit 459dd836 authored by Jens Segers's avatar Jens Segers

More features

parent 904654dc
......@@ -20,40 +20,6 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
*/
protected $primaryKey = '_id';
/**
* Perform a model insert operation.
*
* @param \Illuminate\Database\Eloquent\Builder
* @return bool
*/
protected function performInsert($query)
{
if ($this->fireModelEvent('creating') === false) return false;
$attributes = $this->attributes;
// If the model has an incrementing key, we can use the "insertGetId" method on
// the query builder, which will give us back the final inserted ID for this
// table from the database. Not all tables have to be incrementing though.
if ($this->incrementing)
{
$keyName = $this->getKeyName();
$this->setAttribute($keyName, $query->insert($attributes));
}
// If the table is not incrementing we'll simply insert this attributes as they
// are, as this attributes arrays must contain an "id" column already placed
// there by the developer as the manually determined key for these models.
else
{
$query->insert($attributes);
}
$this->fireModelEvent('created', false);
return true;
}
/**
* Get a new query builder instance for the connection.
*
......
......@@ -123,6 +123,18 @@ class Query extends \Illuminate\Database\Query\Builder {
}
}
/**
* Insert a new record and get the value of the primary key.
*
* @param array $values
* @param string $sequence
* @return int
*/
public function insertGetId(array $values, $sequence = null)
{
return $this->insert($values);
}
/**
* Update a record in the database.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment