Class: RPCMapper::Association::BelongsTo

Inherits:
Base
  • Object
show all
Defined in:
lib/rpc_mapper/association.rb

Instance Attribute Summary

Attributes inherited from Base

#id, #options, #source_klass

Instance Method Summary collapse

Methods inherited from Base

#eager_loadable?, #initialize, #primary_key, #target_klass

Constructor Details

This class inherits a constructor from RPCMapper::Association::Base

Instance Method Details

#collection?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/rpc_mapper/association.rb', line 78

def collection?
  false
end

#foreign_keyObject



82
83
84
# File 'lib/rpc_mapper/association.rb', line 82

def foreign_key
  super || "#{id}_id".to_sym
end

#polymorphic?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/rpc_mapper/association.rb', line 86

def polymorphic?
  !!options[:polymorphic]
end

#scope(object) ⇒ Object

Returns a scope on the target containing this association

Builds conditions on top of the base_scope generated from any finder options set with the association

belongs_to :foo, :foreign_key => :foo_id

In addition to any finder options included with the association options the following scope will be added:

where(:id => source[:foo_id])


98
99
100
# File 'lib/rpc_mapper/association.rb', line 98

def scope(object)
  base_scope(object).where(self.primary_key => object[self.foreign_key]) if object[self.foreign_key]
end

#typeObject



74
75
76
# File 'lib/rpc_mapper/association.rb', line 74

def type
  :belongs_to
end