Reputation: 19695
Hi I'm using a polymorphic relation in laravel: official doc
Basically, the idea is in to be able to invite to several object a user ( Tournament, Team, Asociation, Club, etc...)
So, my "Invitation" table is like:
(id, object_id, object_type, user_id, other_fields)
Where object_type is the name of the class ( 'App\Tournament','App\Team', etc) and object_id the FK.
But this way, I don't know how to use object_id as a MySQL ( MariaDB ) Foreign Key, is it posible???
Upvotes: 0
Views: 732
Reputation: 3315
It's not possible, the whole idea behind polymorphism is that the object_id
field is not pointing to a single other table.
You can't say that object_id
reference id
on table 'X' because that's not always the case.
Upvotes: 1