diff --git a/app/models/alt_style.rb b/app/models/alt_style.rb index 4671c0dd..d437bd9b 100644 --- a/app/models/alt_style.rb +++ b/app/models/alt_style.rb @@ -17,6 +17,20 @@ class AltStyle < ApplicationRecord species_human_name: species.human_name) end + # If the series_name hasn't yet been set manually by support staff, show the + # string "" instead. But it won't be searchable by that string—that is, + # `fits:-faerie-draik` intentionally will not work, and the canonical + # filter name will be `fits:alt-style-IDNUMBER`, instead. + def series_name + self[:series_name] || "" + end + + # You can use this to check whether `series_name` is returning the actual + # value or its placeholder value. + def has_real_series_name? + self[:series_name].present? + end + def adjective_name "#{series_name} #{color.human_name}" end diff --git a/db/migrate/20240227233743_change_default_for_alt_styles_series_name.rb b/db/migrate/20240227233743_change_default_for_alt_styles_series_name.rb new file mode 100644 index 00000000..359f9524 --- /dev/null +++ b/db/migrate/20240227233743_change_default_for_alt_styles_series_name.rb @@ -0,0 +1,6 @@ +class ChangeDefaultForAltStylesSeriesName < ActiveRecord::Migration[7.1] + def change + change_column_null :alt_styles, :series_name, true + change_column_default :alt_styles, :series_name, from: "", to: nil + end +end diff --git a/db/schema.rb b/db/schema.rb index 81c41f62..d066d8d0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,14 +10,14 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_27_231815) do +ActiveRecord::Schema[7.1].define(version: 2024_02_27_233743) do create_table "alt_styles", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.integer "species_id", null: false t.integer "color_id", null: false t.integer "body_id", null: false t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false - t.string "series_name", default: "", null: false + t.string "series_name" t.index ["color_id"], name: "index_alt_styles_on_color_id" t.index ["species_id"], name: "index_alt_styles_on_species_id" end