dongpo2002
2014-01-26 07:54
浏览 52
已采纳

Laravel 4:数据透视表或ID

users
id
email
password
created_at
updated_at

tasks
id
name
created_at
updated_at

Should I create a pivot table (users_tasks), or just put a user_id field within the tasks table? I'd like to use the Eloquent driver, but I'm not sure which method would be the most appropriate for these kinds of relationships...

Many-to-many relations are a more complicated relationship type. An example of such a relationship is a user with many roles, where the roles are also shared by other users. For example, many users may have the role of "Admin".

From that quote on the Laravel documentation, it stands to reason that in this scenario, there is no need for a pivot table... since each task is only owned by a single user ... is that the right way of thinking?

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

  users 
id 
email 
password 
created_at 
updated_at 
 
tasks 
id 
name 
created_at  
updated_at 
   
 
 

我应该创建数据透视表( users_tasks ),还是只在其中放入 user_id 字段 tasks 表? 我想使用Eloquent驱动程序,但我不确定哪种方法最适合这种关系......

Many-to - 很多关系是一种更复杂的关系类型。 这种关系的一个例子是具有许多角色的用户,其中 角色也由其他用户共享。 例如,许多用户可能具有“Admin”角色。

根据Laravel文档中的引用,可以理解在这种情况下, 不需要数据透视表......因为每个任务只由一个用户拥有...是正确的思维方式吗?

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

1条回答 默认 最新

相关推荐 更多相似问题