Commit b5e54941 authored by Taylor Otwell's avatar Taylor Otwell

Merge pull request #1410 from franzliedke/patch-56

Make insert_get_id() work with non-auto-incrementing columns.
parents 875cac6c b88c9144
...@@ -810,11 +810,11 @@ class Query { ...@@ -810,11 +810,11 @@ class Query {
} }
/** /**
* 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 array $values
* @param string $column * @param string $column
* @return int * @return mixed
*/ */
public function insert_get_id($values, $column = 'id') public function insert_get_id($values, $column = 'id')
{ {
...@@ -822,7 +822,12 @@ class Query { ...@@ -822,7 +822,12 @@ class Query {
$result = $this->connection->query($sql, array_values($values)); $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; return (int) $result[0]->$column;
} }
......
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