Merge pull request #1410 from franzliedke/patch-56

Make insert_get_id() work with non-auto-incrementing columns.
This commit is contained in:
Taylor Otwell 2013-01-05 12:41:39 -08:00
commit b5e5494144
1 changed files with 8 additions and 3 deletions

View File

@ -810,11 +810,11 @@ public function insert($values)
}
/**
* Insert an array of values into the database table and return the ID.
* Insert an array of values into the database table and return the key.
*
* @param array $values
* @param string $column
* @return int
* @return mixed
*/
public function insert_get_id($values, $column = 'id')
{
@ -822,7 +822,12 @@ public function insert_get_id($values, $column = 'id')
$result = $this->connection->query($sql, array_values($values));
if ($this->grammar instanceof Postgres)
// If the key is not auto-incrementing, we will just return the inserted value
if (isset($values[$column]))
{
return $values[$column];
}
else if ($this->grammar instanceof Postgres)
{
return (int) $result[0]->$column;
}