class ActiveForce::Association::HasManyAssociation

Private Instance Methods

default_foreign_key() click to toggle source
# File lib/active_force/association/has_many_association.rb, line 6
def default_foreign_key
  infer_foreign_key_from_model @parent
end
define_relation_method() click to toggle source
# File lib/active_force/association/has_many_association.rb, line 10
def define_relation_method
  association = self
  _method = @relation_name
  @parent.send :define_method, _method do
    association_cache.fetch _method do
      query = association.relation_model.query
      if scope = association.options[:scoped_as]
        if scope.arity > 0
          query.instance_exec self, &scope
        else
          query.instance_exec &scope
        end
      end
      association_cache[_method] = query.where association.foreign_key => self.id
    end
  end

  @parent.send :define_method, "#{_method}=" do |associated|
    association_cache[_method] = associated
  end
end