Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Auto increment ID values #10

Description

@clphillips

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions