aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorBrian Samson <brian@briansamson.com>2011-11-24 13:11:33 -0700
committerBrian Samson <brian@briansamson.com>2011-11-25 08:24:54 -0700
commit0f5104d7208b706e9a0353d3d4ccb20683e81bde (patch)
treeafd001da9f2174039014a8a41afc559f139a2e4d /activerecord/lib
parent0cd3bf84068dd2b2d0bbb26062f2cdc7093a1b04 (diff)
downloadrails-0f5104d7208b706e9a0353d3d4ccb20683e81bde.tar.gz
rails-0f5104d7208b706e9a0353d3d4ccb20683e81bde.tar.bz2
rails-0f5104d7208b706e9a0353d3d4ccb20683e81bde.zip
load has_many associations keyed off a custom primary key if that key is present but the record is unsaved
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb2
-rw-r--r--activerecord/lib/active_record/associations/has_many_association.rb4
2 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 362f1053cd..af37909c89 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -235,7 +235,7 @@ module ActiveRecord
# This method is abstract in the sense that it relies on
# +count_records+, which is a method descendants have to provide.
def size
- if owner.new_record? || (loaded? && !options[:uniq])
+ if !find_target? || (loaded? && !options[:uniq])
target.size
elsif !loaded? && options[:group]
load_target.size
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb
index 3353cdf1ef..c5b90e873a 100644
--- a/activerecord/lib/active_record/associations/has_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_association.rb
@@ -103,6 +103,10 @@ module ActiveRecord
end
end
end
+
+ def foreign_key_present?
+ owner.attribute_present?(reflection.association_primary_key)
+ end
end
end
end