Module: Housekeeping::AssociationHelpers
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/housekeeping/association_helpers.rb
Instance Method Summary collapse
-
#has_many_relationship_classes ⇒ Array of Classes
The non-abstract has_many Classes for this instance.
-
#has_many_relationships ⇒ Array of Strings
The non-abstract has_many class names for this instance.
Instance Method Details
#has_many_relationship_classes ⇒ Array of Classes
Returns 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 |
#has_many_relationships ⇒ Array of Strings
Returns 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 |