users
id
email
password
created_at
updated_at
tasks
id
name
created_at
updated_at
code> pre>
我应该创建数据透视表( users_tasks code>),还是只在其中放入 user_id code>字段 tasks code>表? 我想使用Eloquent驱动程序,但我不确定哪种方法最适合这种关系...... p>
Many-to - 很多关系是一种更复杂的关系类型。 这种关系的一个例子是具有许多角色的用户,其中
角色也由其他用户共享。 例如,许多用户可能具有“Admin”角色。 p>
blockquote>
根据Laravel文档中的引用,可以理解在这种情况下, 不需要数据透视表......因为每个任务 code>只由一个用户 code>拥有...是正确的思维方式吗? p>
div>
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?