This repository was archived by the owner on Nov 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Auto increment ID values #10
Copy link
Copy link
Open
Description
Random IDs might be okay for testing, but seeding generally requires that table IDs increment in the order they were inserted.
This can be accomplished by assigning a count to each item in a table fixture and referencing the count when inserting.
// apples.php
return [
// ID: 1
'Granny-Smith' => [
'color' => 'green',
'description' => 'Tart'
],
// ID: 2
'Red Delicious' => [
'color' => 'red',
'description' => 'Slightly Tart'
]
];So when we insert a foreign key:
// apple_sauces.php
return [
// ID: 1
'Treetop' => [
'apple_id' => 'Red Delicious' // foreign key ID 1
],
// ID: 2
'Kirkland' => [
'apple_id' => 'Red Delicious' // foreign key ID 1
]
];Obviously requires preprocessing all fixtures.
Here's an alternative (allow integer values to be assigned as foreign keys):
// apple_sauces.php
return [
// ID: 1
'Treetop' => [
'apple_id' => 1
],
// ID: 2
'Kirkland' => [
'apple_id' => 1
]
];Metadata
Metadata
Assignees
Labels
No labels