aboutsummaryrefslogblamecommitdiffstats
path: root/activerecord/lib/active_record/associations/preloader/singular_association.rb
blob: f60647a81e710a214ce64d9a7ee3da41439b77f1 (plain) (tree)
1
2
3
4
5
6
7
8
9






                                                      

                                                                                    



                                                            
                                                              






             
module ActiveRecord
  module Associations
    class Preloader
      class SingularAssociation < Association #:nodoc:

        private

        def preload(preloader)
          associated_records_by_owner(preloader).each do |owner, associated_records|
            record = associated_records.first

            association = owner.association(reflection.name)
            association.target = record
            association.set_inverse_instance(record) if record
          end
        end

      end
    end
  end
end