Problem to attach on relationManager

Hello,

I have a problem attaching one model to another with the relationmanager.

This is my model :
class Competition extends Model { public function squads() { return $this->belongsToMany(Squad::class)->join('clubs', 'club_id', '=', 'clubs.id')->orderBy('clubs.name'); } }

class Squad extends Model { public function club() { return $this->belongsTo(Club::class); } }

I have a RelationManager :

class SquadsRelationManager extends RelationManager { protected static string $relationship = 'squads'; protected static ?string $recordTitleAttribute = 'clubs.name'; public function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('club.name'), ]) } }

The club names are displayed correctly on the competition edit page, but when I want to associate a new club, I do a search in the club name list, and I get an error "Undefined property: stdClass::$name".

I don't know which "name" property is causing the problem.

Is it possible to add it like I did? I'm just starting out with Filament.

Thanks for your help.
(sorry for my english)
Solution
Thank you, it's OK with this code :

Tables\Actions\AttachAction::make() ->recordSelectSearchColumns(['clubs.name']) ->recordTitle(fn (Squad $record): string => "{$record->club->name} ({$record->id})"),
Was this page helpful?