Table Laravel Eloquent hasManyThrough 关系的命名约定

Table naming convention for Laravel Eloquent hasManyThrough relation

主要实体Subject有多个CommentComment有多个Rate

我应该如何命名迁移 tables?

我用谷歌搜索了 hasMany 关系的命名是 subjectssubject_comment

Rate table 应该命名为 subject_comment_ratesubject_comments_ratecomment_rate 吗?

默认情况下 laravel pivot tables 遵循按字母顺序使用单数名称命名 table 的惯例,因此如果您想遵循惯例,您应该命名您的 table就像这样:

  • 科目
  • 评论
  • comment_subject
  • 费率
  • comment_rate

您可以偏离此约定,但您必须在设置关系时指定枢轴的名称table