Module: Granite::Form::Model::Associations::ClassMethods

Defined in:
lib/granite/form/model/associations.rb

Instance Method Summary collapse

Instance Method Details

#alias_association(alias_name, association_name) ⇒ Object

Raises:

  • (ArgumentError)


58
59
60
61
62
63
64
65
# File 'lib/granite/form/model/associations.rb', line 58

def alias_association(alias_name, association_name)
  reflection = reflect_on_association(association_name)
  raise ArgumentError, "Can't alias undefined association `#{attribute_name}` on #{self}" unless reflection

  reflection.class.generate_methods alias_name, generated_associations_methods
  self._association_aliases = _association_aliases.merge(alias_name.to_sym => reflection.name)
  reflection
end

#association_namesObject



72
73
74
# File 'lib/granite/form/model/associations.rb', line 72

def association_names
  _associations.keys
end

#reflect_on_association(name) ⇒ Object



67
68
69
70
# File 'lib/granite/form/model/associations.rb', line 67

def reflect_on_association(name)
  name = name.to_sym
  _associations[_association_aliases[name] || name]
end

#reflectionsObject



54
55
56
# File 'lib/granite/form/model/associations.rb', line 54

def reflections
  _associations
end