Module: Housekeeping::AssociationHelpers

Extended by:
ActiveSupport::Concern
Included in:
Project, User
Defined in:
lib/housekeeping/association_helpers.rb

Instance Method Summary (collapse)

Instance Method Details

- (Array of Classes) has_many_relationship_classes

Returns the non-abstract has_many Classes for this instance

Returns:

  • (Array of Classes)

    the non-abstract has_many Classes for this instance



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/housekeeping/association_helpers.rb', line 21

def has_many_relationship_classes
  Rails.application.eager_load!
  relationships = []

  self.class.reflect_on_all_associations(:has_many).each do |r|
    name = r.name.to_s
    if self.respond_to?(r.name) && !r.klass.abstract_class? 
      relationships.push r.klass
    end
  end
  relationships.sort{|a,b| a.name <=> b.name}
end

- (Array of Strings) has_many_relationships

Returns the non-abstract has_many class names for this instance

Returns:

  • (Array of Strings)

    the non-abstract has_many class names for this instance



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/housekeeping/association_helpers.rb', line 6

def has_many_relationships
  Rails.application.eager_load!
  relationships = []

  self.class.reflect_on_all_associations(:has_many).each do |r|
    name = r.name.to_s
    if self.respond_to?(r.name) && !r.klass.abstract_class? 
      relationships.push name
    end
  end
  relationships.sort
end