update summon model and blueprint for series lookup
This commit is contained in:
parent
c4e42b0968
commit
e1d212c764
2 changed files with 29 additions and 0 deletions
|
|
@ -16,6 +16,19 @@ module Api
|
||||||
s.promotion_names
|
s.promotion_names
|
||||||
end
|
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|
|
field :uncap do |s|
|
||||||
{
|
{
|
||||||
flb: s.flb,
|
flb: s.flb,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
class Summon < ApplicationRecord
|
class Summon < ApplicationRecord
|
||||||
include PgSearch::Model
|
include PgSearch::Model
|
||||||
|
|
||||||
|
belongs_to :summon_series, optional: true
|
||||||
|
|
||||||
multisearchable against: %i[name_en name_jp],
|
multisearchable against: %i[name_en name_jp],
|
||||||
additional_attributes: lambda { |summon|
|
additional_attributes: lambda { |summon|
|
||||||
{
|
{
|
||||||
|
|
@ -65,4 +67,18 @@ class Summon < ApplicationRecord
|
||||||
def promotion_names
|
def promotion_names
|
||||||
promotions.filter_map { |p| GranblueEnums::PROMOTIONS.key(p)&.to_s }
|
promotions.filter_map { |p| GranblueEnums::PROMOTIONS.key(p)&.to_s }
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue