19 lines
480 B
Ruby
19 lines
480 B
Ruby
module SDG::Relatable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
has_many :sdg_relations, as: :relatable, dependent: :destroy, class_name: "SDG::Relation"
|
|
|
|
%w[SDG::Goal SDG::Target SDG::LocalTarget].each do |sdg_type|
|
|
has_many sdg_type.constantize.table_name.to_sym,
|
|
through: :sdg_relations,
|
|
source: :related_sdg,
|
|
source_type: sdg_type
|
|
end
|
|
end
|
|
|
|
def related_sdgs
|
|
sdg_relations.map(&:related_sdg)
|
|
end
|
|
end
|