【发布时间】:2013-03-23 06:16:56
【问题描述】:
这是我的能力定义:
can :manage,Order,:store => {:business_district => {:district_manager_id => user.id}}
当我通过以下方式加载资源时:
Order.accessible_by(current_ability)
它生成这样的 SQL:
SELECT COUNT(*) FROM `orders` INNER JOIN `stores` ON `stores`.`id` = `orders`.`store_id` INNER JOIN `business_districts` ON `business_districts`.`id` = `stores`.`business_district_id` WHERE (`stores`.`business_districts` = '---\n:district_manager_id: 37\n')
除了“where”中的代码外,sql 看起来都不错。 我不知道如何使它工作 这是模型关系
1. store belongs_to business_district
2. order belongs_to store
3. business_district has district_manager_id
我想查看 business_district 中的所有订单
我在so中找到了一个关于这个的话题:[CanCan深度嵌套资源
但是在cancan中使用块定义时,不能使用accessible_by(current_ability)加载资源!
你可以使用Order.joins(:store => :business_district).where("district_manager_id = ?",current_user.id)来加载我想要的! cancan gem 有什么办法可以做到这一点?
【问题讨论】:
标签: sql ruby-on-rails cancan