1
0
Fork 0

Merge branch 'atomaka/feature/link-counter-cache' into 'master'

Add counter cache for links

It is difficult to find out which cards are missing links.  This allows us to easily find those cards.

See merge request !18
This commit is contained in:
Andrew Tomaka 2015-11-03 14:37:22 -05:00
commit 59384c0b85
3 changed files with 17 additions and 2 deletions

View file

@ -12,7 +12,7 @@ class Card < ActiveRecord::Base
belongs_to :awaken_type belongs_to :awaken_type
belongs_to :dokkan_card, class_name: 'Card', foreign_key: :dokkan_id belongs_to :dokkan_card, class_name: 'Card', foreign_key: :dokkan_id
has_and_belongs_to_many :links has_and_belongs_to_many :links, counter_cache: true
has_many :evidences has_many :evidences

View file

@ -0,0 +1,14 @@
class AddLinksCounterCacheToCards < ActiveRecord::Migration
def up
add_column :cards, :links_count, :integer, default: 0, null: false
Card.reset_column_information
Card.find_each do |card|
card.update_attribute(:links_count, card.links.count)
end
end
def down
remove_column :cards, :links_count
end
end

View file

@ -11,7 +11,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.define(version: 20151020212132) do ActiveRecord::Schema.define(version: 20151103193404) do
create_table "awaken_types", force: :cascade do |t| create_table "awaken_types", force: :cascade do |t|
t.string "name" t.string "name"
@ -36,6 +36,7 @@ ActiveRecord::Schema.define(version: 20151020212132) do
t.integer "hp_stat_id" t.integer "hp_stat_id"
t.integer "atk_stat_id" t.integer "atk_stat_id"
t.integer "def_stat_id" t.integer "def_stat_id"
t.integer "links_count", default: 0, null: false
end end
add_index "cards", ["awaken_type_id"], name: "index_cards_on_awaken_type_id" add_index "cards", ["awaken_type_id"], name: "index_cards_on_awaken_type_id"