aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorRajinder Yadav <devguy.ca@gmail.com>2010-10-15 22:19:39 -0400
committerRajinder Yadav <devguy.ca@gmail.com>2010-10-15 22:19:39 -0400
commit62eb00a62e3868c3500372def52968b919332b51 (patch)
tree8497f517402c19eae1fea22943565cbf11496ef7 /activerecord/lib/active_record/associations
parent018bf0f5756ef3887815ea46d6671dc1d3b526cf (diff)
parentcffae06a4f1b7aac86a7e99cfb244890f837f976 (diff)
downloadrails-62eb00a62e3868c3500372def52968b919332b51.tar.gz
rails-62eb00a62e3868c3500372def52968b919332b51.tar.bz2
rails-62eb00a62e3868c3500372def52968b919332b51.zip
Merge branch 'master' of git://github.com/lifo/docrails
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb12
-rw-r--r--activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb2
2 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index 91e0a9f2f8..cb2d9e0a79 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -363,6 +363,7 @@ module ActiveRecord
def include?(record)
return false unless record.is_a?(@reflection.klass)
+ return include_in_memory?(record) if record.new_record?
load_target if @reflection.options[:finder_sql] && !loaded?
return @target.include?(record) if loaded?
exists?(record)
@@ -554,6 +555,17 @@ module ActiveRecord
args.first.kind_of?(Hash) || !(loaded? || @owner.new_record? || @reflection.options[:finder_sql] ||
@target.any? { |record| record.new_record? } || args.first.kind_of?(Integer))
end
+
+ def include_in_memory?(record)
+ if @reflection.is_a?(ActiveRecord::Reflection::ThroughReflection)
+ @owner.send(proxy_reflection.through_reflection.name.to_sym).any? do |source|
+ target = source.send(proxy_reflection.source_reflection.name)
+ target.respond_to?(:include?) ? target.include?(record) : target == record
+ end
+ else
+ @target.include?(record)
+ end
+ end
end
end
end
diff --git a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
index 38454ec242..e429806b0c 100644
--- a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
+++ b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb
@@ -39,7 +39,7 @@ module ActiveRecord
def set_inverse_instance(record, instance)
return if record.nil? || !we_can_set_the_inverse_on_this?(record)
inverse_relationship = @reflection.polymorphic_inverse_of(record.class)
- unless inverse_relationship.nil?
+ if inverse_relationship
record.send(:"set_#{inverse_relationship.name}_target", instance)
end
end