【发布时间】:2020-01-28 15:11:36
【问题描述】:
我正在为一个软件构建一个数据库,其中身份验证与公司的 LDAP 服务器相结合。 我现在有两张桌子
AD_Groups
和
AD_Users
在表中加入了哪些
AD_UsersXAD_Groups
我已经学会了如何用 eloquent 建立关系。 官方文档中举例说明了多对多关系: https://laravel.com/docs/5.8/eloquent-relationships#many-to-many
现在,如您所见,eloquent 的以下功能对我没有多大帮助:
"To define this relationship, three database tables are needed: users, roles, and role_user. The role_user table is derived from the alphabetical order of the related model names, and contains the user_id and role_id columns."
因此,我需要使用第二个参数覆盖这个派生名称,如下所述:
"As mentioned previously, to determine the table name of the relationship's joining 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:
return $this->belongsToMany('App\Role', 'role_user');
但是从上面的文档示例中可以看出,臭名昭著的“蛇形案例”仍然应用于名称。
但是,我担心这可能不适用于我的情况。
诚然,AD_UsersXAD_Groups 非常丑陋,我担心 eloquent/lumen 将无法正确识别其元素并正确应用蛇案例规则。
但我不确定,因此我问你什么最有可能奏效。
使用AD_UsersXAD_Groups 或AD_UserXAD_Group
【问题讨论】:
-
如果您提供第二个参数,据我所知,eloquent 将逐字使用它,所以只需提供您的确切表名
标签: php laravel eloquent lumen