开发者

Rails - Named scopes

开发者 https://www.devze.com 2023-02-06 16:29 出处:网络
for my user\'s model I have: class User < ActiveRecord::Base has_many :group_users, :class_name => \"User\", :finder_sql => \'select DISTINCT u.* from users u join permissions pp on pp.user_

for my user's model I have:

class User < ActiveRecord::Base
  has_many :group_users, :class_name => "User", :finder_sql => 'select DISTINCT u.* from users u join permissions pp on pp.user_id=u.id join spaces p 开发者_开发问答on pp.space_id=p.id where space_id in (select space_id from permissions pp2 where user_id=#{id}) and pp.user_id != #{id}'

How can I access that in a scope like:

  scope :usersInMySpaces, lambda { |user|
      group_users
  }

thanks


You can't and there's no point. has_many associations act like scopes in many cases but in this one the finder_sql is so complicated that it couldn't be combined with any other sql as a scope.

0

精彩评论

暂无评论...
验证码 换一张
取 消