简体   繁体   中英

I want to write following query rails way

select DISTINCT firstname 
  from users u 
    inner join  members m 
      on m.user_id = u.id 
    inner join  member_roles m1 
      on m1.member_id = m.id 
    inner join roles r
      on r.id = m1.role_id  
  where r.name  = 'Project Coordinator'

this gives perfect result

I tried to write above query rails way like

s = MemberRole.joins(:role).where("roles.name" => "Project Coordinator")

@u = User.select("users.firstname").includes(:members => s )

but seems doesnt work any help?? thanks in advance

User.select("users.firstname").includes(:members => [{:member_roles => :role}]).where("roles.name" => "Project Coordinator")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM