require "../setup"
battle = Swars::Battle.create!(strike_plan: "角不成")
battle.reload
sql
# tp battle
# tp battle.memberships[0].badge_info
# tp battle.memberships[0].taggings.first.tag.name # => "筋違い角"

# battle.memberships.first.taggings.loaded? # => false
# battle.memberships.first.taggings.to_a    # => [#<ActsAsTaggableOn::Tagging id: 423, tag_id: 36, taggable_type: "Swars::Membership", taggable_id: 77, tagger_type: nil, tagger_id: nil, context: "attack_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 424, tag_id: 37, taggable_type: "Swars::Membership", taggable_id: 77, tagger_type: nil, tagger_id: nil, context: "attack_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 428, tag_id: 41, taggable_type: "Swars::Membership", taggable_id: 77, tagger_type: nil, tagger_id: nil, context: "note_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 425, tag_id: 38, taggable_type: "Swars::Membership", taggable_id: 77, tagger_type: nil, tagger_id: nil, context: "technique_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 426, tag_id: 39, taggable_type: "Swars::Membership", taggable_id: 77, tagger_type: nil, tagger_id: nil, context: "technique_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 427, tag_id: 40, taggable_type: "Swars::Membership", taggable_id: 77, tagger_type: nil, tagger_id: nil, context: "technique_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">]
# battle.memberships.includes(taggings: :tag).first.taggings.loaded? # => true
# battle.memberships.collect { |e| e.taggings } # => [#<ActiveRecord::Associations::CollectionProxy [#<ActsAsTaggableOn::Tagging id: 423, tag_id: 36, taggable_type: "Swars::Membership", taggable_id: 77, tagger_type: nil, tagger_id: nil, context: "attack_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 424, tag_id: 37, taggable_type: "Swars::Membership", taggable_id: 77, tagger_type: nil, tagger_id: nil, context: "attack_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 428, tag_id: 41, taggable_type: "Swars::Membership", taggable_id: 77, tagger_type: nil, tagger_id: nil, context: "note_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 425, tag_id: 38, taggable_type: "Swars::Membership", taggable_id: 77, tagger_type: nil, tagger_id: nil, context: "technique_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 426, tag_id: 39, taggable_type: "Swars::Membership", taggable_id: 77, tagger_type: nil, tagger_id: nil, context: "technique_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 427, tag_id: 40, taggable_type: "Swars::Membership", taggable_id: 77, tagger_type: nil, tagger_id: nil, context: "technique_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">]>, #<ActiveRecord::Associations::CollectionProxy [#<ActsAsTaggableOn::Tagging id: 429, tag_id: 37, taggable_type: "Swars::Membership", taggable_id: 78, tagger_type: nil, tagger_id: nil, context: "attack_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 434, tag_id: 41, taggable_type: "Swars::Membership", taggable_id: 78, tagger_type: nil, tagger_id: nil, context: "note_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 430, tag_id: 42, taggable_type: "Swars::Membership", taggable_id: 78, tagger_type: nil, tagger_id: nil, context: "technique_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 431, tag_id: 40, taggable_type: "Swars::Membership", taggable_id: 78, tagger_type: nil, tagger_id: nil, context: "technique_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 432, tag_id: 43, taggable_type: "Swars::Membership", taggable_id: 78, tagger_type: nil, tagger_id: nil, context: "technique_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">, #<ActsAsTaggableOn::Tagging id: 433, tag_id: 38, taggable_type: "Swars::Membership", taggable_id: 78, tagger_type: nil, tagger_id: nil, context: "technique_tags", created_at: "2025-08-10 10:40:34.000000000 +0900">]>]

# tp battle.memberships.includes(taggings: :tag)[0].taggings.first.tag.name # => "筋違い角"
# tp battle.memberships.includes(taggings: :tag)[0].taggings.first.tag.name # => "筋違い角"

m = battle.memberships[0]
m.taggings.loaded?              # => false
m.taggings.includes(:tag).pluck(:name)       # => ["筋違い角", "相筋違い角", "短手数", "角不成", "手損", "角交換"]

# >>   Swars::Membership Load (0.7ms)  SELECT `swars_memberships`.* FROM `swars_memberships` WHERE `swars_memberships`.`battle_id` = 55 ORDER BY `swars_memberships`.`position` ASC /*application='ShogiWeb'*/
# >>   ActsAsTaggableOn::Tagging Pluck (0.5ms)  SELECT `name` FROM `taggings` LEFT OUTER JOIN `tags` ON `tags`.`id` = `taggings`.`tag_id` WHERE `taggings`.`taggable_id` = 109 AND `taggings`.`taggable_type` = 'Swars::Membership' /*application='ShogiWeb'*/
