开发者

one-to-many relation in Kohana

开发者 https://www.devze.com 2023-03-20 06:57 出处:网络
I have 3 tables users , roles and roles_users. The roles_users table have user_id and role_id N开发者_JS百科ow my models are Model_User, Model_Role, Model_User_Role.

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

N开发者_JS百科ow my models are 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.

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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消