Class: Id::Model::Association

Inherits:
Field
  • Object
show all
Defined in:
lib/id/model/association.rb

Direct Known Subclasses

HasMany, HasOne

Defined Under Namespace

Classes: Hierarchy

Instance Attribute Summary

Attributes inherited from Field

#model, #name, #options

Instance Method Summary collapse

Methods inherited from Field

#cast, #default, #default?, #default_value, #define, #hook_define, #initialize, #key, #optional?, #presence_of, #value_of

Constructor Details

This class inherits a constructor from Id::Model::Field

Instance Method Details

#hierarchyObject



17
18
19
# File 'lib/id/model/association.rb', line 17

def hierarchy
  @hierarchy ||= Hierarchy.new(model.name, inferred_class_name)
end

#inferred_classObject



9
10
11
# File 'lib/id/model/association.rb', line 9

def inferred_class
  hierarchy.parent.const_get(inferred_class_name)
end

#inferred_class_nameObject



13
14
15
# File 'lib/id/model/association.rb', line 13

def inferred_class_name
  @inferred_class_name ||= name.to_s.classify
end

#typeObject



5
6
7
# File 'lib/id/model/association.rb', line 5

def type
  options.fetch(:type) { inferred_class }
end