@@ -48,20 +48,20 class Principal < ActiveRecord::Base | |||||
48 | scope :member_of, lambda {|projects| |
|
48 | scope :member_of, lambda {|projects| | |
49 | projects = [projects] unless projects.is_a?(Array) |
|
49 | projects = [projects] unless projects.is_a?(Array) | |
50 | if projects.empty? |
|
50 | if projects.empty? | |
51 | {:conditions => "1=0"} |
|
51 | where("1=0") | |
52 | else |
|
52 | else | |
53 | ids = projects.map(&:id) |
|
53 | ids = projects.map(&:id) | |
54 |
|
|
54 | 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) | |
55 | end |
|
55 | end | |
56 | } |
|
56 | } | |
57 | # Principals that are not members of projects |
|
57 | # Principals that are not members of projects | |
58 | scope :not_member_of, lambda {|projects| |
|
58 | scope :not_member_of, lambda {|projects| | |
59 | projects = [projects] unless projects.is_a?(Array) |
|
59 | projects = [projects] unless projects.is_a?(Array) | |
60 | if projects.empty? |
|
60 | if projects.empty? | |
61 | {:conditions => "1=0"} |
|
61 | where("1=0") | |
62 | else |
|
62 | else | |
63 | ids = projects.map(&:id) |
|
63 | ids = projects.map(&:id) | |
64 |
|
|
64 | where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids) | |
65 | end |
|
65 | end | |
66 | } |
|
66 | } | |
67 |
|
67 |
General Comments 0
You need to be logged in to leave comments.
Login now