Unconventional Pivot table name. How to tell the Relation manager to use this table name ?
I have a many to many relationship between my Customer Model and Chatter Model and a Pivot class unconventionaly named ChattingInstance. I created a RelationManager for the CustomerResource named ChattersRelationManager but the DB request failed because it tries to use the conventional table name for the Pivot class which should be name chatter_customer. How I can force to use the right table name which is 'chatting_instances' ?
4 Replies
@taz there are two static strings "$relationship" and "$inverseRelationship" where you can set custom relationship names for the RelationManager
Thanks you for your anwser. I already tried that. But for the relationship and inverseRelationship the naming is normal, so the DB request is good. The only part of the request that is wrong is for the pivot table name for the many to many relation between my Customer Model and Chatter Model. Filament tries to do the inner join with the table named
chatter_customer
while my table is named chatting_instances
. I can't figure out how to change this behaviour@taz have you tried passing in the table name to your belongsToMany() call? Something like:
return $this->belongsToMany( Customer::class, 'chatting_instances' )->...
@nanopanda thanks a lot for your help, that was it. It's not even related to Filament, it's Eloquent that determines the pivot table name for the DB request and it's clearly written in the Laravel Documentation :
To determine the table name of the relationship's intermediate table, Eloquent will join the two related model names in alphabetical order. However, you are free to override this convention. You may do so by passing a second argument to the belongsToMany method