Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Associate and Dissociate actions don't work with a MorphMany relationship #14556

Closed
rfiette opened this issue Oct 17, 2024 · 2 comments
Closed
Labels

Comments

@rfiette
Copy link

rfiette commented Oct 17, 2024

Package

filament/filament

Package Version

v3.2.117

Laravel Version

v11.27.2

Livewire Version

No response

PHP Version

php 8.2

Problem description

Associate and Dissociate actions don't work with a MorphMany relationship. I got an error :
Capture d'écran 2024-10-17 190634
Capture d'écran 2024-10-17 191450

I have 3 models : Client, Entreprise and Interlocuteur.

Relations between them are :
Client :
public function interlocuteurs(): MorphMany { return $this->morphMany(Interlocuteur::class, 'interlocuteurable'); }

Entreprise :
public function interlocuteurs(): MorphMany { return $this->morphMany(Interlocuteur::class, 'interlocuteurable'); }

Interlocuteur :
public function interlocuteurable(): MorphTo { return $this->morphTo(); }

Expected behavior

The record should be dettached from the Client or Entreprise.

Steps to reproduce

Create a user
Create a Client record
Create a Entreprise record
Create an interlocuteur attached to a Client or a Entreprise
Try to dissociate the Interlocuteur

Reproduction repository (issue will be closed if this is not valid)

https://github.com/rfiette/FilamentMorphBug2

Relevant log output

No response

@kalrav-vardaam
Copy link

In your InterlocuteursRelationManager class under table function try adding this line $table->inverseRelationship('interlocuteurable');

This is because Filament is unable to locate inverse relation when it's morphTo or MorphToMany.

@danharrin
Copy link
Member

Thanks @kalrav-vardaam

@danharrin danharrin closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in Roadmap Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

3 participants