Sha256: 1e100301be68f2261929e30c99c32a6e7195a7c6f0b30c8e36413d4aaf319fa7

Contents?: true

Size: 1.33 KB

Versions: 17

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Torque
  module PostgreSQL
    module Associations
      module Association

        # There is no problem of adding temporary items on target because
        # CollectionProxy will handle memory and persisted relationship
        def inversed_from(record)
          return super unless reflection.connected_through_array?

          self.target ||= []
          self.target.push(record) unless self.target.include?(record)
          @inversed = self.target.present?
        end

        # The binds and the cache are getting mixed and caching the wrong query
        def skip_statement_cache?(*)
          super || reflection.connected_through_array?
        end

        private

          # This is mainly for the has many when connect through an array to add
          # its id to the list of the inverse belongs to many association
          def set_owner_attributes(record)
            return super unless reflection.connected_through_array?

            add_id = owner[reflection.active_record_primary_key]
            list = record[reflection.foreign_key] ||= []
            list.push(add_id) unless list.include?(add_id)
          end

      end

      ::ActiveRecord::Associations::Association.prepend(Association)
      ::ActiveRecord::Associations::HasManyAssociation.prepend(Association)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
torque-postgresql-2.4.5 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.4.4 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.4.3 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.4.2 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.4.1 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.4.0 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.3.0 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.2.4 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.2.3 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.2.2 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.2.1 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.2.0 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.1.3 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.1.2 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.1.1 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.1.0 lib/torque/postgresql/associations/association.rb
torque-postgresql-2.0.6 lib/torque/postgresql/associations/association.rb