#Bug in foreignIdFor?

9 messages · Page 1 of 1 (latest)

hard geyser
#

I have a Project model defining

    protected $primaryKey = 'codename';
    public $incrementing = false;
    protected $keyType = 'string';

I have another model, and writing the migration for it I do:

            $table->foreignIdFor(Project::class, 'project_id');

But I get an error. If I debug this method, there's no handling at all for strings, just int, UUIDs or ULIDs.

As a workaround I can do:

            $table->string('project_id');
            $table->foreignId('project_id')
                ->type('string')
                ->change()
                ->references('codename')
                ->on('projects')->onDelete('cascade');

But shouldn't foreignIdFor just work with strings?
I might be missing something, I'm pretty new to laravel.

velvet drift
#

Not a bug

#

Avoid strings as FK

#

For performance reasons

hard geyser
#

ULIDs are already strings and they are supported. We can have indexes. Reads are more common than Writes. I might be inheriting a data model.
Looks quite opinionated to not support this.

velvet drift
#

The underlying data type is different

#

They don’t take the same bytes

velvet drift
hard geyser
#

so char good, varchar bad