2016-05-30 15:00
浏览 178

Laravel Eloquent的表命名约定hasManyThrough关系

The main entity Subject has multiple Comment's, and the Comment has multiple Rate's.

How should I name the migration tables?

I've googled that the naming for hasMany relation is subjects and subject_comment.

Should the Rate table be named subject_comment_rate or subject_comments_rate or comment_rate?

图片转代码服务由CSDN问答提供 功能建议

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


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

Rate 表是否应命名为 subject_comment_rate subject_comments_rate comment_rate

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duan1983 2016-05-30 15:21

    By default laravel pivot tables follow the convetion of naming the table in alphabetical order with singular names so if you want to follow the convention you should name your tables like so:

    • subjects
    • comments
    • comment_subject
    • rates
    • comment_rate

    You can deviate from this convention but then you have to specify the name of the pivot table when setting up the relationship

    解决 无用
    打赏 举报

相关推荐 更多相似问题