framework icon indicating copy to clipboard operation
framework copied to clipboard

[11.x] Fix type mismatch in Polymorphic Relationships When Using PostgreSQL

Open crynobone opened this issue 10 months ago • 0 comments

fixes #54401

The changes introduce a "string" default morph type via schema and eloquent relationship.

Global

To combine uuid or ulid with int globally.

Illuminate\Database\Schema\Builder::defaultMorphKeyType('string');

Per relationship

Alternatively, you can manually set it per table using either $table->nullableStringableMorphs('owner') or $table->stringableMorphs('owner') method.

Next, define the relationship using:

public function integrations()
{
    return $this->morphMany(Owner::class, 'owner', morphKeyType: 'string');
}

or

public function integrations()
{
    return $this->morphMany(Owner::class, 'owner')->morphKeyType('string');
}

crynobone avatar Jan 30 '25 09:01 crynobone