diff --git a/app/models/concerns/has_content_groupers.rb b/app/models/concerns/has_content_groupers.rb index 61c54650..862dc6c4 100644 --- a/app/models/concerns/has_content_groupers.rb +++ b/app/models/concerns/has_content_groupers.rb @@ -4,6 +4,8 @@ module HasContentGroupers extend ActiveSupport::Concern included do + @@relations = {} + # Example: # relates :siblings, with: :siblingships, where: { alive: true }, type: :two_way # Defines :siblings and :siblingships relations, their inverses, and accepts_nested_attributes for siblingships @@ -12,6 +14,13 @@ module HasContentGroupers connecting_class = with.to_s.singularize.camelize.constantize connecting_class_name = with + # Store all added relations on the class model, so we can dynamically fetch them all whenever needed. + # e.g. Character.class_variable_get(:@@relations) => [:mothers, :fathers, :siblings, ...] + @@relations[relation] = { # @@relations[:siblings] = { + with: with, # with: :siblingships, + related_class: connecting_class # related_class: Siblingship + } # } + # Siblingships has_many connecting_class_name