diff --git a/lib/Model.php b/lib/Model.php index 6164f8d35..52cdf2e58 100644 --- a/lib/Model.php +++ b/lib/Model.php @@ -848,7 +848,7 @@ private function insert($validate=true) $column = $table->get_column_by_inflected_name($pk); if ($column->auto_increment || $use_sequence) - $this->attributes[$pk] = static::connection()->insert_id($table->sequence); + $this->attributes[$pk] = $column->cast(static::connection()->insert_id($table->sequence), static::connection()); } $this->__new_record = false; diff --git a/test/ActiveRecordWriteTest.php b/test/ActiveRecordWriteTest.php index 48c156c34..863929339 100644 --- a/test/ActiveRecordWriteTest.php +++ b/test/ActiveRecordWriteTest.php @@ -194,6 +194,18 @@ public function test_dirty_attributes() $this->assert_equals(array('name','special'),array_keys($book->dirty_attributes())); } + public function test_id_type() + { + $book = new Book; + $book->save(); + + $bookFromFind = Book::find($book->id); + + // both should be ints + $this->assert_same($book->id, $bookFromFind->id); + } + + public function test_dirty_attributes_cleared_after_saving() { $book = $this->make_new_book_and();