diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-01-24 23:55:14 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-01-30 11:58:08 +0000 |
commit | 59d54c3ebaa08c3298a36d1655a2492074ed8a87 (patch) | |
tree | c40e52d7d377823afbca562fe8613875e1c4d5d4 | |
parent | 0645fd2c80c05109f148e28cdf78d636406cb6d7 (diff) | |
download | rails-59d54c3ebaa08c3298a36d1655a2492074ed8a87.tar.gz rails-59d54c3ebaa08c3298a36d1655a2492074ed8a87.tar.bz2 rails-59d54c3ebaa08c3298a36d1655a2492074ed8a87.zip |
Make AssociationCollection#include? a bit more readable
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index b1a8d772f3..2811f53424 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -297,10 +297,16 @@ module ActiveRecord end 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? - loaded? ? @target.include?(record) : exists?(record) + if record.is_a?(@reflection.klass) + if record.new_record? + include_in_memory?(record) + else + load_target if @reflection.options[:finder_sql] + loaded? ? @target.include?(record) : scoped.exists?(record) + end + else + false + end end def respond_to?(method, include_private = false) |