Patrick Star
Patrick Star
FFilament
Created by Patrick Star on 3/25/2024 in #❓┊help
RelationManager Call to undefined method HasMany::getQualifiedRelatedKeyName
Hey, i do experience issues while implementing a RelationManager for my Filament application that i can not wrap my head around. I do have a "Container" model that should be able to be related to other Containers - it does have a parent_id column as well as a parent (BelongsTo) & children (HasMany) relationship. However, when i try to "put one Container into the other" by attaching it, i do get the following exception: https://flareapp.io/share/LPdKbvdm#context
I really don't understand why it does try to call getQualifiedRelatedKeyName as this method has been removed from the Relation implementation in Laravel 5.5. This is how i have defined the relationship column in my migration:
Schema::create('containers', function (Blueprint $table) {
$table->id();

$table->foreignId('parent_id')
->nullable()
->constrained('containers');

$table->timestamps();
});
Schema::create('containers', function (Blueprint $table) {
$table->id();

$table->foreignId('parent_id')
->nullable()
->constrained('containers');

$table->timestamps();
});
This is how i have implemented the relationships on the Container Model:
class Container extends Model
{
/**
* The parent Container this Container is stored in.
*/
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id');
}

/**
* The child Containers that are stored in this Container.
*/
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_id');
}
}
class Container extends Model
{
/**
* The parent Container this Container is stored in.
*/
public function parent(): BelongsTo
{
return $this->belongsTo(self::class, 'parent_id');
}

/**
* The child Containers that are stored in this Container.
*/
public function children(): HasMany
{
return $this->hasMany(self::class, 'parent_id');
}
}
This is how i have implemented the RelationManager:
class MyRelationManager extends RelationManager
{
protected static string $relationship = 'children';

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
// ...
->inverseRelationship('parent');
}
}
class MyRelationManager extends RelationManager
{
protected static string $relationship = 'children';

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
// ...
->inverseRelationship('parent');
}
}
Does anyone have an idea on what i am doing wrong? I do appreciate any help 🙂 Thank you
4 replies