otwarchive-side-pairings/app/models/relationship.rb

72 lines
1.4 KiB
Ruby
Raw Normal View History

2026-11-17 04:19:14 +00:00
class Relationship < Tag
NAME = ArchiveConfig.RELATIONSHIP_CATEGORY_NAME
def works
main_work_ids = Tagging.where(
tagger_type: "Tag",
tagger_id: id,
taggable_type: "Work"
).select(:taggable_id)
side_work_ids = WorkSidePairing.where(
relationship_id: id
).select(:work_id)
Work.where(id: main_work_ids).or(
Work.where(id: side_work_ids)
)
end
def taggings_count
main_work_ids = Tagging.where(
tagger_type: "Tag",
tagger_id: id,
taggable_type: "Work"
).select(:taggable_id)
side_pairing_count = WorkSidePairing.where(
relationship_id: id
).where.not(work_id: main_work_ids).count
super + side_pairing_count
end
def parent_types
['Fandom', 'Character', 'MetaTag']
end
def child_types
['SubTag', 'Merger']
end
def characters
parents.by_type('Character').by_name
end
def all_characters
all = self.characters
if self.merger
all << self.merger.characters
end
all_with_synonyms = all.flatten.uniq.compact
all_with_synonyms << all_with_synonyms.collect{|c| c.mergers}
all_with_synonyms.flatten.uniq.compact
end
def relationships
(parents + children).select {|t| t.is_a? Relationship}.sort
end
def freeforms
children.by_type('Freeform').by_name
end
def fandoms
parents.by_type('Fandom').by_name
end
def medias
parents.by_type('Media').by_name
end
end