Laravel Eloquent的表命名约定hasManyThrough关系

时间:2016-05-30 15:00:22

标签: php laravel eloquent naming-conventions

主要实体Subject有多个Comment个,Comment有多个Rate个。

我应该如何命名迁移表?

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

Rate表应该命名为subject_comment_rate还是subject_comments_rate还是comment_rate

1 个答案:

答案 0 :(得分:1)

默认情况下,laravel数据透视表遵循使用单数名称按字母顺序命名表格的方式,因此如果您想遵循约定,则应按照以下方式命名表格:

  • 受试者
  • 评论
  • comment_subject
  • comment_rate

您可以偏离此约定,但在设置关系时必须指定数据透视表的名称