[英]FK in a Laravel polymorphic relation
Hi I'm using a polymorphic relation in laravel: official doc 嗨,我在laravel中使用了多态关系: 官方文档
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. 其中object_type是类的名称(“ App \\ Tournament”,“ App \\ Team”等),而object_id是FK。
But this way, I don't know how to use object_id as a MySQL ( MariaDB ) Foreign Key, is it posible??? 但是这样,我不知道如何使用object_id作为MySQL(MariaDB)外键,这可能吗?
It's not possible, the whole idea behind polymorphism is that the object_id
field is not pointing to a single other table. 多态性背后的整个想法是不可能的,那就是
object_id
字段没有指向另一个表。
You can't say that object_id
reference id
on table 'X' because that's not always the case. 您不能在表'X'上说
object_id
引用id
,因为并非总是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.