diff options
author | Jon Leighton <j@jonathanleighton.com> | 2010-12-24 00:29:04 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2010-12-26 19:38:04 +0000 |
commit | e8ada11aac28f0850f0e485acacf34e7eb81aa19 (patch) | |
tree | 8d336ca01b37d42bdaa904d00f3b7daa11e24e84 /activerecord/lib/active_record/associations/through_association_scope.rb | |
parent | f2230c06edf9c1ca72892bbe00e816be1dafa840 (diff) | |
download | rails-e8ada11aac28f0850f0e485acacf34e7eb81aa19.tar.gz rails-e8ada11aac28f0850f0e485acacf34e7eb81aa19.tar.bz2 rails-e8ada11aac28f0850f0e485acacf34e7eb81aa19.zip |
Associations: DRY up the code which is generating conditions, and make it all use arel rather than SQL strings
Diffstat (limited to 'activerecord/lib/active_record/associations/through_association_scope.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/through_association_scope.rb | 22 |
1 files changed, 2 insertions, 20 deletions
diff --git a/activerecord/lib/active_record/associations/through_association_scope.rb b/activerecord/lib/active_record/associations/through_association_scope.rb index 415fc53e1c..1abeb178ff 100644 --- a/activerecord/lib/active_record/associations/through_association_scope.rb +++ b/activerecord/lib/active_record/associations/through_association_scope.rb @@ -51,26 +51,8 @@ module ActiveRecord @reflection.through_reflection.klass.arel_table end - # Build SQL conditions from attributes, qualified by table name. - def construct_conditions - table = aliased_through_table - conditions = construct_owner_attributes(@reflection.through_reflection).map do |attr, value| - table[attr].eq(value) - end - conditions << Arel.sql(sql_conditions) if sql_conditions - table.create_and(conditions) - end - - # Associate attributes pointing to owner - def construct_owner_attributes(reflection) - if as = reflection.options[:as] - { "#{as}_id" => @owner[reflection.active_record_primary_key], - "#{as}_type" => @owner.class.base_class.name } - elsif reflection.macro == :belongs_to - { reflection.klass.primary_key => @owner[reflection.primary_key_name] } - else - { reflection.primary_key_name => @owner[reflection.active_record_primary_key] } - end + def construct_owner_conditions + super(aliased_through_table, @reflection.through_reflection) end def construct_select |