Code cleanup.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10804 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-11-13 22:15:47 +00:00
parent 547b85c4ef
commit b880020527
1 changed files with 4 additions and 4 deletions

View File

@ -48,20 +48,20 @@ class Principal < ActiveRecord::Base
scope :member_of, lambda {|projects| scope :member_of, lambda {|projects|
projects = [projects] unless projects.is_a?(Array) projects = [projects] unless projects.is_a?(Array)
if projects.empty? if projects.empty?
{:conditions => "1=0"} where("1=0")
else else
ids = projects.map(&:id) ids = projects.map(&:id)
{:conditions => ["#{Principal.table_name}.status = 1 AND #{Principal.table_name}.id IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids]} where("#{Principal.table_name}.status = 1 AND #{Principal.table_name}.id IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
end end
} }
# Principals that are not members of projects # Principals that are not members of projects
scope :not_member_of, lambda {|projects| scope :not_member_of, lambda {|projects|
projects = [projects] unless projects.is_a?(Array) projects = [projects] unless projects.is_a?(Array)
if projects.empty? if projects.empty?
{:conditions => "1=0"} where("1=0")
else else
ids = projects.map(&:id) ids = projects.map(&:id)
{:conditions => ["#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids]} where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
end end
} }