method

remove_duplicate_results!

Importance_0
Ruby on Rails latest stable (v7.1.3.2) - 0 notes - Class: ActiveRecord::Associations::ClassMethods::JoinDependency

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v3.0.9) is shown here.

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 1893
          def remove_duplicate_results!(base, records, associations)
            case associations
              when Symbol, String
                reflection = base.reflections[associations]
                remove_uniq_by_reflection(reflection, records)
              when Array
                associations.each do |association|
                  remove_duplicate_results!(base, records, association)
                end
              when Hash
                associations.keys.each do |name|
                  reflection = base.reflections[name]
                  remove_uniq_by_reflection(reflection, records)

                  parent_records = []
                  records.each do |record|
                    if descendant = record.send(reflection.name)
                      if reflection.collection?
                        parent_records.concat descendant.target.uniq
                      else
                        parent_records << descendant
                      end
                    end
                  end

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