F
Filamentβ€’3mo ago
Patrick Star

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
Flare
Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::getQualifiedRelatedKeyName() - The error occurred at http://localhost/app/containers/1/edit
Solution:
Ok, nevermind - i have to use the AssociateAction instead of the AttachAction πŸ‘€
Jump to solution
1 Reply
Solution
Patrick Star
Patrick Starβ€’3mo ago
Ok, nevermind - i have to use the AssociateAction instead of the AttachAction πŸ‘€