update summon model and blueprint for series lookup

This commit is contained in:
Justin Edmund 2025-12-14 11:58:34 -08:00
parent c4e42b0968
commit e1d212c764
2 changed files with 29 additions and 0 deletions

View file

@ -16,6 +16,19 @@ module Api
s.promotion_names
end
field :series do |s|
if s.summon_series.present?
{
id: s.summon_series_id,
slug: s.summon_series.slug,
name: {
en: s.summon_series.name_en,
ja: s.summon_series.name_jp
}
}
end
end
field :uncap do |s|
{
flb: s.flb,

View file

@ -3,6 +3,8 @@
class Summon < ApplicationRecord
include PgSearch::Model
belongs_to :summon_series, optional: true
multisearchable against: %i[name_en name_jp],
additional_attributes: lambda { |summon|
{
@ -65,4 +67,18 @@ class Summon < ApplicationRecord
def promotion_names
promotions.filter_map { |p| GranblueEnums::PROMOTIONS.key(p)&.to_s }
end
def series_slug
summon_series&.slug
end
# Virtual attribute to set summon_series by ID or slug
# Supports both UUID and slug lookup for flexibility
def series=(value)
return self.summon_series = nil if value.blank?
# Try to find by ID first, then by slug
found = SummonSeries.find_by(id: value) || SummonSeries.find_by(slug: value)
self.summon_series = found
end
end