Sha256: 2ee57092cf8af29f97fd77a784f81e357875ff7a68c36f22b52416c6b9e9bf77

Contents?: true

Size: 878 Bytes

Versions: 13

Compression:

Stored size: 878 Bytes

Contents

module ActiveForce
  module Association
    class HasManyAssociation < Association
      def sfdc_association_field
        name = relationship_name.gsub(/__c\z/, '__r')
        match = name.match(/__r\z/)
        # pluralize the table name, and append '__r' if it was there to begin with
        name.sub(match.to_s, '').pluralize + match.to_s
      end

      private

      def default_foreign_key
        infer_foreign_key_from_model parent
      end

      def target(owner)
        apply_scope(relation_model.query, owner).where(foreign_key => owner.id)
      end

      def target_when_unloadable
        relation_model.none
      end

      def define_assignment_method
        method_name = relation_name
        parent.send :define_method, "#{method_name}=" do |associated|
          association_cache[method_name] = associated
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
active_force-0.24.0 lib/active_force/association/has_many_association.rb
active_force-0.23.0 lib/active_force/association/has_many_association.rb
active_force-0.22.1 lib/active_force/association/has_many_association.rb
active_force-0.22.0 lib/active_force/association/has_many_association.rb
active_force-0.21.0 lib/active_force/association/has_many_association.rb
active_force-0.20.1 lib/active_force/association/has_many_association.rb
active_force-0.20.0 lib/active_force/association/has_many_association.rb
active_force-0.19.0 lib/active_force/association/has_many_association.rb
active_force-0.18.0 lib/active_force/association/has_many_association.rb
active_force-0.17.0 lib/active_force/association/has_many_association.rb
active_force-0.16.0 lib/active_force/association/has_many_association.rb
active_force-0.15.1 lib/active_force/association/has_many_association.rb
active_force-0.15.0 lib/active_force/association/has_many_association.rb