AttachAction doesn't work
I have a simple one-to-many relation between Clients and Contacts. I want to select existing contacts for a Client from the RelationManager.
If I use the AttachAction from the Header Actions I get an error, which is available here:
https://flareapp.io/share/lm2DjkL7#F70
Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::getRelatedKeyName()
Not sure what I am doing wrong?Flare
Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::getRelatedKeyName() - The error occurred at https://careerguide.test:8443/admin/clients/46/edit
14 Replies
Your relation should be a BelongsToMany
Hmm... It is
One Client
that Has Many Contacts
? Not sure I understand.
This is in my Client model:
And this is in my Contact model:
you need AssociateAction
its in the docs
I tried. It gives me the same error
please send that error then
Sorry, not entirely the same: https://flareapp.io/share/47qrk2E5#F75
Flare
Call to undefined method App\Models\Contact::clients() - The error occurred at https://careerguide.test:8443/admin/clients/46/edit
protected static ?string $inverseRelationship = 'client';
Is that a workaround, or something that I need anyways? I just try to understand what I am doing wrong. The HasMany should be the right relationship type, right?
It something you need if the guessed relationship doesn't match
OK.
I'll try it.
I still think it's a BelongsToMany, but I might be wrong π
I see you point now. Maybe you are right. If it is just one-to-many the CreateAction would be sufficient. With a Many-To-Many you would need the AttachAction I guess.
I don't have a pivot table.
Sorry, I led you astray following a completely different relationship type π
you have a one-to-many
AssociateAction is for when you have contacts with client_id=null and want to associate them to the current client