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)


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

def alias_association(alias_name, association_name)
  reflection = reflect_on_association(association_name)
  raise ArgumentError.new("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



68
69
70
# File 'lib/active_data/model/associations.rb', line 68

def association_names
  _associations.keys
end

#reflect_on_association(name) ⇒ Object



63
64
65
66
# File 'lib/active_data/model/associations.rb', line 63

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

#reflectionsObject



51
52
53
# File 'lib/active_data/model/associations.rb', line 51

def reflections
  _associations
end