Sha256: 8d87cf555d58f63c55e2cdd7f8cb5dc71ff2d69af155e5c377f9c2b286583f10

Contents?: true

Size: 825 Bytes

Versions: 11

Compression:

Stored size: 825 Bytes

Contents

module DbCharmer
  module AssociationPreload
    module ClassMethods
      ASSOCIATION_TYPES = [ :has_one, :has_many, :belongs_to, :has_and_belongs_to_many ]

      def self.extended(base)
        ASSOCIATION_TYPES.each do |association_type|
          base.class_eval <<-EOF, __FILE__, __LINE__ + 1
            def self.preload_#{association_type}_association(records, reflection, preload_options = {})
              if self.db_charmer_top_level_connection? || self.db_charmer_default_connection != reflection.klass.db_charmer_default_connection
                return super(records, reflection, preload_options)
              end
              reflection.klass.on_db(self) do
                super(records, reflection, preload_options)
              end
            end
          EOF
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
db-charmer-1.6.19 lib/db_charmer/association_preload.rb
db-charmer-1.6.18 lib/db_charmer/association_preload.rb
db-charmer-1.6.17 lib/db_charmer/association_preload.rb
db-charmer-1.6.16 lib/db_charmer/association_preload.rb
db-charmer-1.6.15 lib/db_charmer/association_preload.rb
db-charmer-1.6.14 lib/db_charmer/association_preload.rb
db-charmer-1.6.13 lib/db_charmer/association_preload.rb
db-charmer-1.6.12 lib/db_charmer/association_preload.rb
db-charmer-1.6.11 lib/db_charmer/association_preload.rb
db-charmer-1.6.10 lib/db_charmer/association_preload.rb
db-charmer-1.6.9 lib/db_charmer/association_preload.rb