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)


128
129
130
# File 'lib/rpc_mapper/association.rb', line 128

def collection?
  false
end

#foreign_keyObject



132
133
134
# File 'lib/rpc_mapper/association.rb', line 132

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

#polymorphic?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/rpc_mapper/association.rb', line 136

def polymorphic?
  !!options[:polymorphic]
end

#polymorphic_typeObject



140
141
142
# File 'lib/rpc_mapper/association.rb', line 140

def polymorphic_type
  "#{id}_type".to_sym
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])


156
157
158
159
160
# File 'lib/rpc_mapper/association.rb', line 156

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

#typeObject



124
125
126
# File 'lib/rpc_mapper/association.rb', line 124

def type
  :belongs_to
end