aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/through_association_scope.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-12-14 15:24:25 -0800
committerVijay Dev <vijaydev.cse@gmail.com>2010-12-16 01:49:29 +0530
commit2f0708e97405fa55e641dd2eac8805f12f878f5a (patch)
tree24df58409951fa335f83bf56e5595289f91a4f4d /activerecord/lib/active_record/associations/through_association_scope.rb
parentaa4d03fcfc42453b5553c001d24933365effe5f0 (diff)
downloadrails-2f0708e97405fa55e641dd2eac8805f12f878f5a.tar.gz
rails-2f0708e97405fa55e641dd2eac8805f12f878f5a.tar.bz2
rails-2f0708e97405fa55e641dd2eac8805f12f878f5a.zip
build SQL AST nodes rather than generate strings
Diffstat (limited to 'activerecord/lib/active_record/associations/through_association_scope.rb')
-rw-r--r--activerecord/lib/active_record/associations/through_association_scope.rb18
1 files changed, 8 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/through_association_scope.rb b/activerecord/lib/active_record/associations/through_association_scope.rb
index f6b242168c..8d701248af 100644
--- a/activerecord/lib/active_record/associations/through_association_scope.rb
+++ b/activerecord/lib/active_record/associations/through_association_scope.rb
@@ -23,25 +23,23 @@ module ActiveRecord
# Build SQL conditions from attributes, qualified by table name.
def construct_conditions
- table_name = @reflection.through_reflection.quoted_table_name
+ table = @reflection.through_reflection.klass.arel_table
conditions = construct_quoted_owner_attributes(@reflection.through_reflection).map do |attr, value|
- "#{table_name}.#{attr} = #{value}"
+ table[attr].eq(value)
end
- conditions << sql_conditions if sql_conditions
- "(" + conditions.join(') AND (') + ")"
+ conditions << Arel.sql(sql_conditions) if sql_conditions
+ table.create_and(conditions)
end
# Associate attributes pointing to owner, quoted.
def construct_quoted_owner_attributes(reflection)
if as = reflection.options[:as]
- { "#{as}_id" => owner_quoted_id,
- "#{as}_type" => reflection.klass.quote_value(
- @owner.class.base_class.name.to_s,
- reflection.klass.columns_hash["#{as}_type"]) }
+ { "#{as}_id" => @owner.id,
+ "#{as}_type" => @owner.class.base_class.name }
elsif reflection.macro == :belongs_to
- { reflection.klass.primary_key => @owner.class.quote_value(@owner[reflection.primary_key_name]) }
+ { reflection.klass.primary_key => @owner[reflection.primary_key_name] }
else
- { reflection.primary_key_name => owner_quoted_id }
+ { reflection.primary_key_name => @owner.id }
end
end