Kohana ORM 关系问题
我有桌子:
users {id, name} projects {id, name} roles {id, name} projects_users {id, user_id, project_id, role_id}
我有模型:
project { has many users through projects_users } user { has many projects through projects_users }
问题: 如何获取一个项目的用户角色?或者也许我必须重建我的桌子?
代码:
$project = ORM::factory('project', $id); $users = $project->users->find_all(); foreach ($users as $u) { $roles = $u-> .... How to get all roles for this user and for this project? }
I have tables:
users {id, name} projects {id, name} roles {id, name} projects_users {id, user_id, project_id, role_id}
I have models:
project { has many users through projects_users } user { has many projects through projects_users }
Question:
How i get user roles for one project? Or maybe i have to reconstruct my tables?
Code:
$project = ORM::factory('project', $id); $users = $project->users->find_all(); foreach ($users as $u) { $roles = $u-> .... How to get all roles for this user and for this project? }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的project_users表似乎代表项目中的角色,添加与该表相关的另一个模型:
然后您可以执行以下操作:
如果这不起作用,则以下之一应该可以工作,但可能是另一种形式遍历到你想要的东西。
或者
Your project_users table seems to be representing roles on projects, add another model which is tied to that table:
Then you might be able to do:
If that doesn't work, one of the following should work, but may be a different form of traversal to what you're after.
Or