pacecar 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pacecar/associations.rb +1 -1
- data/lib/pacecar/ranking.rb +2 -2
- metadata +1 -1
data/lib/pacecar/associations.rb
CHANGED
@@ -31,7 +31,7 @@ module Pacecar
|
|
31
31
|
protected
|
32
32
|
|
33
33
|
def conditions_for_name(name)
|
34
|
-
"((select count(*) from #{connection.quote_table_name(name)} where #{connection.quote_table_name(name)}.#{connection.quote_column_name reflections[name].primary_key_name} = #{quoted_table_name}.#{connection.quote_column_name primary_key} and #{connection.quote_table_name(name)}.#{connection.quote_column_name("created_at")} > :since_time) > 0)"
|
34
|
+
"((select count(*) from #{connection.quote_table_name(name)} where #{connection.quote_table_name(name)}.#{connection.quote_column_name (reflections[name].respond_to?(:foreign_key) ? reflections[name].foreign_key : reflections[name].primary_key_name)} = #{quoted_table_name}.#{connection.quote_column_name primary_key} and #{connection.quote_table_name(name)}.#{connection.quote_column_name("created_at")} > :since_time) > 0)"
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
data/lib/pacecar/ranking.rb
CHANGED
@@ -27,7 +27,7 @@ module Pacecar
|
|
27
27
|
|
28
28
|
def define_ranking_scope(association, direction_name, direction)
|
29
29
|
scope "#{direction_name}_#{association}", {
|
30
|
-
:select => "#{quoted_table_name}.*, count(#{reflections[association].quoted_table_name}.#{connection.quote_column_name reflections[association].primary_key_name}) as #{association}_count",
|
30
|
+
:select => "#{quoted_table_name}.*, count(#{reflections[association].quoted_table_name}.#{connection.quote_column_name (reflections[association].respond_to?(:foreign_key) ? reflections[association].foreign_key : reflections[association].primary_key_name)}) as #{association}_count",
|
31
31
|
:order => "#{association}_count #{direction}"
|
32
32
|
}.merge(association_group_and_join(association))
|
33
33
|
end
|
@@ -43,7 +43,7 @@ module Pacecar
|
|
43
43
|
|
44
44
|
def association_group_and_join(association_name)
|
45
45
|
{
|
46
|
-
:joins => "inner join #{connection.quote_table_name(association_name)} on #{connection.quote_table_name(association_name)}.#{connection.quote_column_name reflections[association_name].primary_key_name} = #{quoted_table_name}.#{connection.quote_column_name primary_key}",
|
46
|
+
:joins => "inner join #{connection.quote_table_name(association_name)} on #{connection.quote_table_name(association_name)}.#{connection.quote_column_name (reflections[association_name].respond_to?(:foreign_key) ? reflections[association_name].foreign_key : reflections[association_name].primary_key_name)} = #{quoted_table_name}.#{connection.quote_column_name primary_key}",
|
47
47
|
:group => safe_column_names.collect { |column_name| "#{quoted_table_name}.#{connection.quote_column_name(column_name)}" }.join(', ')
|
48
48
|
}
|
49
49
|
end
|