Pivot-Table with Morph-Relation?
Hello,
I have a Contract Model with a ContractResource and a Cluster Model with ClusterResoruce. Now I have a pivot table betweem them called cluster_contract with some normal attributs. Working just fine to attach them, edit pivot columns, etc. No problems here.
But now, the pivot table clust_contract, has again a morph relation to the model "County". So, I have a table clustercontractable with cluster_contract_id, _type, _id, columns, etc..
In the contract's relation for clusters() am doing a using() on a ClusterContract class extending the Pivot class. Doing this also to add casts to the pivot attributes, which also worked fine.
But if I now, add the counties() morphedBy relation to the ClusterContract class and add the
Forms\Components\Select::make('counties')
->label('Landkreise')
->multiple()
->preload()
->relationship('counties', 'name'),
to the resource, I get the error Call to a member function getResults() on null
in vendor/filament/forms/src/Components/Select.php:889.
I made some debugging and the reason for this error is, that Filament tries to find the relation "counties" on the model "Cluster" and not on the pivot table "ClusterContract". Makes sense.
But... I also have fields in this resource like ::make('email'), etc.. and here Filament automatically detects, that I want to address the pivot's attribute email and not the Cluster attribute.
Is there a way to tell Filament, that with counties, I mean the relation on the ClusterContract table, and not on the Cluster table?
Thanks a lot!1 Reply
May, there is anyway, to pass to the Select::relationship() function not only the name of the relation, but also the information, that I want to address this relation on the pivot table and not on one of the n:m tables.