method

remove_duplicate_results!

Importance_0
v2.3.8 - Show latest stable - 0 notes - Class: ActiveRecord::Associations::ClassMethods::JoinDependency
remove_duplicate_results!(base, records, associations) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/associations.rb, line 1859
          def remove_duplicate_results!(base, records, associations)
            case associations
              when Symbol, String
                reflection = base.reflections[associations]
                if reflection && reflection.collection?
                  records.each { |record| record.send(reflection.name).target.uniq! }
                end
              when Array
                associations.each do |association|
                  remove_duplicate_results!(base, records, association)
                end
              when Hash
                associations.keys.each do |name|
                  reflection = base.reflections[name]

                  parent_records = records.map do |record|
                    descendant = record.send(reflection.name)
                    next unless descendant
                    descendant.target.uniq! if reflection.collection?
                    descendant
                  end.flatten.compact

                  remove_duplicate_results!(reflection.klass, parent_records, associations[name]) unless parent_records.empty?
                end
            end
          end
Register or log in to add new notes.