【问题标题】:Laravel belongsToMany non standard pivot columnLaravel belongsToMany 非标准枢轴列
【发布时间】:2016-08-13 02:55:57
【问题描述】:

我试图设置 BelongsToMany 关系,其中一列不是 ID 引用,而是字符串引用。

return $this->belongsToMany('User', 'chats_users', 'chat_id', 'user_email');

可以这样做吗?

【问题讨论】:

标签: php laravel


【解决方案1】:

只要字符串引用是父表的主键,这应该可以工作,尽管不推荐这样做。请务必查看this explanation on using strings as primary keys

return $this->belongsToMany('User', 'chats_users', 'chat_id', 'user_email');

【讨论】:

    猜你喜欢
    • 2018-08-28
    • 1970-01-01
    • 2019-05-31
    • 2017-04-27
    • 2021-01-08
    • 2023-01-30
    • 1970-01-01
    • 2012-09-23
    • 1970-01-01
    相关资源
    最近更新 更多