diff options
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index cfdd33d6e8..5162f859aa 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1536,8 +1536,10 @@ module ActiveRecord is_collection = [:has_many, :has_and_belongs_to_many].include?(reflection.macro) parent_records = records.map do |record| - next unless record.send(reflection.name) - is_collection ? record.send(reflection.name).target.uniq! : record.send(reflection.name) + descendant = record.send(reflection.name) + next unless descendant + descendant.target.uniq! if is_collection + descendant end.flatten.compact remove_duplicate_results!(reflection.class_name.constantize, parent_records, associations[name]) unless parent_records.empty? |