Laravel 5与外键的多态关系

时间:2016-08-08 10:59:34

标签: php mysql laravel laravel-5 polymorphic-associations

表:

角色

-id
-role

用户

-id
-role_id

学校

-id (primary, foreign-references id on users) 
-other attributes

咨询

-id (primary, foreign-references id on users) 
-other attributes

-id (primary, foreign-references id on users) 
-other attributes

学校,咨询和学生是用户的专业化(或概括?)。

在他们的模型类中,我试图建立多态一对一的关系。如果没有角色表,那么看起来很简单,然后用户表中的role_id已经是string:role。

但是通过这种结构,我如何让关系发挥作用?

0 个答案:

没有答案