Search code examples
ormkohanakohana-3kohana-ormkohana-auth

one-to-many relation in Kohana


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

Now 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.


Solution

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