Related page with unconventional relation to parent

Hi, I'm trying to setup a related page with an unconventional relation to parent. Contact hasMany Bookmarks Bookmarks belongsTo Buyer (Contact) App\Models\Contact.php
public function bookmarks(): HasMany
{
return $this->hasMany(Bookmark::class);
}
public function bookmarks(): HasMany
{
return $this->hasMany(Bookmark::class);
}
App\Models\Bookmark.php
public function buyer(): BelongsTo
{
return $this->belongsTo(Contact::class, 'buyer_id');
}
public function buyer(): BelongsTo
{
return $this->belongsTo(Contact::class, 'buyer_id');
}
I've setup the inverseRelationship on the table call in the related page : ManageContactBookmarks.php
namespace App\Filament\App\Resources\Contacts\Pages;

use ...;

class ManageContactBookmarks extends ManageRelatedRecords
{
protected static string $resource = ContactResource::class;

protected static string $relationship = 'bookmarks';

protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedBookmark;

public function form(Schema $schema): Schema
{
return BookmarkForm::configure($schema);
}

public function table(Table $table): Table
{
return BookmarksTable::configure($table)
->inverseRelationship('buyer');
}
}
namespace App\Filament\App\Resources\Contacts\Pages;

use ...;

class ManageContactBookmarks extends ManageRelatedRecords
{
protected static string $resource = ContactResource::class;

protected static string $relationship = 'bookmarks';

protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedBookmark;

public function form(Schema $schema): Schema
{
return BookmarkForm::configure($schema);
}

public function table(Table $table): Table
{
return BookmarksTable::configure($table)
->inverseRelationship('buyer');
}
}
Bug when i try to open the relationship page i got this 500 error : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'bookmarks.contact_id' in 'WHERE' (Connection: mariadb, SQL: select count(*) as aggregate from bookmarks where bookmarks.contact_id = 01996b34-3e88-723a-91c9-36cbd93c6090 and bookmarks.contact_id is not null and (bookmarks.deleted_at is null) and bookmarks.tenant_id in (01996b34-3d92-72ef-93b0-66e5d7546836)) Seems like it doesn't take into account my relationship to a specific column that doesn't follow convention.
1 Reply
Mathias
MathiasOP2w ago
Ok found it ! Nothing related to Filament. I assumed I needed to specify the specific foreign key, on the belongsTo relationship but it was on the hasMany relationship also.

Did you find this page helpful?