Sql 选择查询数据库
我想执行SQL查询并将结果应用于我的能力类:Sql 选择查询数据库,sql,ruby-on-rails,cancan,Sql,Ruby On Rails,Cancan,我想执行SQL查询并将结果应用于我的能力类: res_sql = "SELECT * FROM people where trainer_id != null and people.user_id = user.id and user.role = 'Trainerone'" sql应该从Typ Sportler返回我可以应用于cancan的对象: can :manage, **:sportler** 我不确定我是否理解你的问题,但也许
res_sql = "SELECT * FROM people
where trainer_id != null and people.user_id = user.id
and user.role = 'Trainerone'"
sql应该从Typ Sportler返回我可以应用于cancan的对象:
can :manage, **:sportler**
我不确定我是否理解你的问题,但也许这能帮你一点忙:
People.joins(:trainer).
includes(:user).
where(user_id: user.id, user: { role: 'Trainerone' })
此代码如下所示:
- 培训师有很多人
- 人员
属于培训师
- 人员
属于用户
是用户表的一列 (根据对象关系,role
和连接中的不同关系
包含中的不同关系(where子句中也是如此)可能需要复数)