aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-08-18 20:02:14 -0300
committerEmilio Tagua <miloops@gmail.com>2009-08-18 20:02:14 -0300
commita09215ee968250963256a39936a4136aeb1b65f6 (patch)
tree6239f633d90af72be771ccd5449add7b7836c849 /activerecord
parenta7178773d2f57454b55b20577091c00327565b67 (diff)
downloadrails-a09215ee968250963256a39936a4136aeb1b65f6.tar.gz
rails-a09215ee968250963256a39936a4136aeb1b65f6.tar.bz2
rails-a09215ee968250963256a39936a4136aeb1b65f6.zip
has_many nullify associations keys using ARel.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/has_many_association.rb18
1 files changed, 9 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb
index 73d3c23cd3..29ba84ee37 100644
--- a/activerecord/lib/active_record/associations/has_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_association.rb
@@ -40,11 +40,11 @@ module ActiveRecord
# we are certain the current target is an empty array. This is a
# documented side-effect of the method that may avoid an extra SELECT.
@target ||= [] and loaded if count == 0
-
+
if @reflection.options[:limit]
count = [ @reflection.options[:limit], count ].min
end
-
+
return count
end
@@ -69,11 +69,11 @@ module ActiveRecord
when :delete_all
@reflection.klass.delete(records.map { |record| record.id })
else
- ids = quoted_record_ids(records)
- @reflection.klass.update_all(
- "#{@reflection.primary_key_name} = NULL",
- "#{@reflection.primary_key_name} = #{owner_quoted_id} AND #{@reflection.klass.primary_key} IN (#{ids})"
- )
+ relation = arel_table(@reflection.table_name)
+ relation.conditions(relation[@reflection.primary_key_name].eq(@owner.id).
+ and(Arel::In.new(relation[@reflection.klass.primary_key], records.map(&:id)))
+ ).update(relation[@reflection.primary_key_name] => nil)
+
@owner.class.update_counters(@owner.id, cached_counter_attribute_name => -records.size) if has_cached_counter?
end
end
@@ -88,11 +88,11 @@ module ActiveRecord
@finder_sql = interpolate_sql(@reflection.options[:finder_sql])
when @reflection.options[:as]
- @finder_sql =
+ @finder_sql =
"#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_id = #{owner_quoted_id} AND " +
"#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_type = #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}"
@finder_sql << " AND (#{conditions})" if conditions
-
+
else
@finder_sql = "#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} = #{owner_quoted_id}"
@finder_sql << " AND (#{conditions})" if conditions