Module: ActiveData::Model::Associations::ClassMethods

Defined in:
lib/active_data/model/associations.rb

Instance Method Summary collapse

Instance Method Details

#alias_association(alias_name, association_name) ⇒ Object

Raises:

  • (ArgumentError)


57
58
59
60
61
62
63
# File 'lib/active_data/model/associations.rb', line 57

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



70
71
72
# File 'lib/active_data/model/associations.rb', line 70

def association_names
  _associations.keys
end

#reflect_on_association(name) ⇒ Object



65
66
67
68
# File 'lib/active_data/model/associations.rb', line 65

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

#reflectionsObject



53
54
55
# File 'lib/active_data/model/associations.rb', line 53

def reflections
  _associations
end