RelationManager creating "Parent" error
Bit of an odd scenario, but this is what suits us better. I have an IP Address model, and a Host model. Now, an IP can obviously only be assigned to one Host, but a Host can have multiple IP addresses.
As such, I have them setup with a BelongsTo relationship on the IP address, and a HasMany relationship on the Host.
Now, I am going into the IPAddressResource View page, and using the relation manager to create a host, but getting the error
Call to undefined method Illuminate\Database\Eloquent\Relations\BelongsTo::save()
Obviously, I'm doing something wrong, but not entirely sure what/how to resolve it
Edit:
I think this may be a bug in the Filament\Tables\Actions\CreateAction class (line 86), calling $relationship->save($record)
when - as this is a BelongsTo, it should be $relationship->associate($record)
Obviously for the majority of use cases of relation managers, save is correct, but I suspect there needs to be some sort of check of the relation type to determine which method to use?8 Replies
if I understand it correctly, you are using a relation manager for a belongs to, which isn't supported https://filamentphp.com/docs/3.x/panels/resources/relation-managers#relation-managers---interactive-tables-underneath-your-resource-forms
if an IP has only one host, there is no need to use a relation manager, but a Select
the relation manager would be used in the inverse relationship, i.e in the HostResource view page, since it can have multiple IPs
Yeah, but an IP is required on the host, and we can have a lot of IP's in the system, so I wanted to just be able to select the IP and create a host and have it assigned automatically.
I can see in the CreateAction class, there's already checks for the type of relation, so, unless I'm mistaken, just a case of add something like
somewhere shortly before line 89?
but why not a Select then?
On the host? Because there will be thousands of ip addresses and I want to be able to choose specifically the ip I want, which I would have done from the IP list, therefore to me, for UX feels nicer to be able to create the host that way
Maybe this plugin fit in your scenario: https://filamentphp.com/plugins/david-varilek-table-select
Filament
Table Select by David Vařílek - Filament
Form component for selecting related records with a Filament Table.
on the IP. for the host resource you can have an IP relation manager
Yeah, I think that's the way I will need to go @Kyrch. Doesn't feel so nice, but with how RM's work, far from a bad experience
of course, you can extend and customize the create action, just make sure not to have a orphan model