Skip to content

Commit 48e6355

Browse files
author
Igor Chepurnoy
committed
fix issues with multiple primary keys
1 parent dc26e19 commit 48e6355

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/ActiveFixture.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,16 @@ public function load(): void
3939
$table = $this->getTable();
4040

4141
foreach ($this->getData() as $alias => $row) {
42-
$primaryKey = DB::table($table)->insertGetId($row);
43-
$this->data[$alias] = array_merge($row, ['id' => $primaryKey]);
42+
if (Schema::hasColumns($this->table, ['id'])) {
43+
$primaryKey = DB::table($table)->insertGetId($row);
44+
$this->data[$alias] = array_merge($row, ['id' => $primaryKey]);
45+
} else {
46+
if (DB::table($table)->insert($row)) {
47+
$this->data[$alias] = $row;
48+
} else {
49+
throw new Exception("Fixture does not loaded for table: {$this->table}");
50+
}
51+
}
4452
}
4553
}
4654

0 commit comments

Comments
 (0)