From b88c9144ec091a3e5d58f5946a3176e6064f5634 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 1 Nov 2012 18:16:44 +0100 Subject: [PATCH] Make insert_get_id() work with non-auto-incrementing columns. --- laravel/database/query.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/laravel/database/query.php b/laravel/database/query.php index 0b2029c1..73e45fe6 100755 --- a/laravel/database/query.php +++ b/laravel/database/query.php @@ -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; }