Merge pull request #58 from jedmund/remove-weapon-count
Fix counter caches
This commit is contained in:
commit
d39dca337b
6 changed files with 35 additions and 4 deletions
|
|
@ -36,6 +36,10 @@ module Api
|
||||||
fields :name, :element, :shortcode, :favorited, :extra,
|
fields :name, :element, :shortcode, :favorited, :extra,
|
||||||
:full_auto, :clear_time, :auto_guard, :created_at, :updated_at
|
:full_auto, :clear_time, :auto_guard, :created_at, :updated_at
|
||||||
|
|
||||||
|
field :remix do |p|
|
||||||
|
p.is_remix
|
||||||
|
end
|
||||||
|
|
||||||
association :raid,
|
association :raid,
|
||||||
blueprint: RaidBlueprint
|
blueprint: RaidBlueprint
|
||||||
|
|
||||||
|
|
@ -67,6 +71,15 @@ module Api
|
||||||
association :accessory,
|
association :accessory,
|
||||||
blueprint: JobAccessoryBlueprint
|
blueprint: JobAccessoryBlueprint
|
||||||
fields :description, :charge_attack, :button_count, :turn_count, :chain_count
|
fields :description, :charge_attack, :button_count, :turn_count, :chain_count
|
||||||
|
|
||||||
|
association :source_party,
|
||||||
|
blueprint: PartyBlueprint,
|
||||||
|
view: :minimal
|
||||||
|
|
||||||
|
# TODO: This should probably be paginated
|
||||||
|
association :remixes,
|
||||||
|
blueprint: PartyBlueprint,
|
||||||
|
view: :collection
|
||||||
end
|
end
|
||||||
|
|
||||||
view :collection do
|
view :collection do
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
class GridCharacter < ApplicationRecord
|
class GridCharacter < ApplicationRecord
|
||||||
belongs_to :party,
|
belongs_to :party,
|
||||||
counter_cache: :weapons_count,
|
counter_cache: :characters_count,
|
||||||
inverse_of: :characters
|
inverse_of: :characters
|
||||||
validates_presence_of :party
|
validates_presence_of :party
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
class GridSummon < ApplicationRecord
|
class GridSummon < ApplicationRecord
|
||||||
belongs_to :party,
|
belongs_to :party,
|
||||||
counter_cache: :weapons_count,
|
counter_cache: :summons_count,
|
||||||
inverse_of: :summons
|
inverse_of: :summons
|
||||||
validates_presence_of :party
|
validates_presence_of :party
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class Party < ApplicationRecord
|
||||||
foreign_key: 'accessory_id',
|
foreign_key: 'accessory_id',
|
||||||
class_name: 'JobAccessory',
|
class_name: 'JobAccessory',
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
belongs_to :skill0,
|
belongs_to :skill0,
|
||||||
foreign_key: 'skill0_id',
|
foreign_key: 'skill0_id',
|
||||||
class_name: 'JobSkill',
|
class_name: 'JobSkill',
|
||||||
|
|
@ -82,6 +82,14 @@ class Party < ApplicationRecord
|
||||||
user.favorite_parties.include? self
|
user.favorite_parties.include? self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_remix
|
||||||
|
self.source_party != nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def remixes
|
||||||
|
Party.where(source_party_id: self.id)
|
||||||
|
end
|
||||||
|
|
||||||
def blueprint
|
def blueprint
|
||||||
PartyBlueprint
|
PartyBlueprint
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddCharacterAndSummonCountsToParty < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
add_column :parties, :characters_count, :integer
|
||||||
|
add_column :parties, :summons_count, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.0].define(version: 2023_01_26_040207) do
|
ActiveRecord::Schema[7.0].define(version: 2023_01_28_091710) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "btree_gin"
|
enable_extension "btree_gin"
|
||||||
enable_extension "pg_trgm"
|
enable_extension "pg_trgm"
|
||||||
|
|
@ -154,6 +154,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_26_040207) do
|
||||||
t.integer "order"
|
t.integer "order"
|
||||||
t.uuid "base_job_id"
|
t.uuid "base_job_id"
|
||||||
t.string "granblue_id"
|
t.string "granblue_id"
|
||||||
|
t.boolean "accessory", default: false
|
||||||
|
t.integer "accessory_type", default: 0
|
||||||
t.index ["base_job_id"], name: "index_jobs_on_base_job_id"
|
t.index ["base_job_id"], name: "index_jobs_on_base_job_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -221,6 +223,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_26_040207) do
|
||||||
t.integer "turn_count"
|
t.integer "turn_count"
|
||||||
t.uuid "source_party_id"
|
t.uuid "source_party_id"
|
||||||
t.uuid "accessory_id"
|
t.uuid "accessory_id"
|
||||||
|
t.integer "characters_count"
|
||||||
|
t.integer "summons_count"
|
||||||
t.index ["accessory_id"], name: "index_parties_on_accessory_id"
|
t.index ["accessory_id"], name: "index_parties_on_accessory_id"
|
||||||
t.index ["job_id"], name: "index_parties_on_job_id"
|
t.index ["job_id"], name: "index_parties_on_job_id"
|
||||||
t.index ["skill0_id"], name: "index_parties_on_skill0_id"
|
t.index ["skill0_id"], name: "index_parties_on_skill0_id"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue