简体   繁体   中英

FK in a Laravel polymorphic relation

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???

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM