Kohana中的一对多关系

时间:2022-05-09 20:17:59

I have 3 tables users , roles and roles_users. The roles_users table have user_id and role_id

我有3个表用户,角色和roles_users。 roles_users表具有user_id和role_id

Now my models are Model_User, Model_Role, Model_User_Role.

现在我的模型是Model_User,Model_Role,Model_User_Role。

How can i link the three models so that every user is associated to one role and one role has many users.

如何链接这三个模型,以便每个用户都与一个角色相关联,一个角色有多个用户。

I am using ORM and i want to display the list of users with the name of there role.

我正在使用ORM,我想显示具有该角色名称的用户列表。

Note: The table i have taken from Auth Module of Kohana.

注意:我从Kohana的Auth Module获取的表格。

2 个解决方案

#1


2  

You can use $_belongs_to, $_has_one and $_has_many arrays to set relationship between the models. Kohana 3 :: ORM Relationships

您可以使用$ _belongs_to,$ _has_one和$ _has_many数组来设置模型之间的关系。 Kohana 3 :: ORM关系

#2


1  

I did a many to many relation with roles and users. And will write business logic that a users will not have more than one roles.

我与角色和用户做了很多关系。并且将编写用户不会拥有多个角色的业务逻辑。

#1


2  

You can use $_belongs_to, $_has_one and $_has_many arrays to set relationship between the models. Kohana 3 :: ORM Relationships

您可以使用$ _belongs_to,$ _has_one和$ _has_many数组来设置模型之间的关系。 Kohana 3 :: ORM关系

#2


1  

I did a many to many relation with roles and users. And will write business logic that a users will not have more than one roles.

我与角色和用户做了很多关系。并且将编写用户不会拥有多个角色的业务逻辑。