Rails - Named scopes
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.
精彩评论