Getting owner record in custom association action

Hello all, I have a book and story tables with a pivot table between the two. I have relationship manager to handle associating and dissociating books and stories. But the pivot table also has other data that needs to be entered when creating an association (order). So I have overridden the form for the associate action like so:
Tables\Actions\AssociateAction::make()
->form([
Forms\Components\Select::make('story_id')->options(Story::query()->pluck('name', 'id'))->required()->label('Story'),
Forms\Components\TextInput::make('order')->numeric()->required()->label('Order'),
]),
Tables\Actions\AssociateAction::make()
->form([
Forms\Components\Select::make('story_id')->options(Story::query()->pluck('name', 'id'))->required()->label('Story'),
Forms\Components\TextInput::make('order')->numeric()->required()->label('Order'),
]),
I am now trying to save all this stuff, but I cannot seem to retrieve the Book I'm currently editing inside the action. Is there a way to do so?
1 Reply
Matteo G
Matteo GOP5mo ago
got it, I just used $this->getOwnerRecord() and then attached the value with the extra values for the pivot table xD Is there another way that would allow me to avoid overriding this behaviour, though ? I have many relationships with this kind of requirements... and same thing with dissociate action; it doesn't seem to work as intended but tries to call dissociate (I'd like it to use detach 😦 )
Want results from more Discord servers?
Add your server