Skip to content

Instantly share code, notes, and snippets.

@ukstudio
Created April 11, 2012 08:40
Show Gist options
  • Save ukstudio/2357972 to your computer and use it in GitHub Desktop.
Save ukstudio/2357972 to your computer and use it in GitHub Desktop.
battle.rb
class User
has_one :character
end
class Character
belongs_to :user
has_many :battles
has_many :battle_records
end
class Battle
has_one :battle_record
end
class BattleRecords
belongs_to :battle
belongs_to :character, :foreign_key => :character_code
end
# 戦闘からキャラクターとる
# Battle.includes(:battle_record => :character).first.battle_record.character
#
# 戦績からキャラクターとる
# BattleRecord.includes(:character).first.character
#
# ユーザーから全部とる
# User.includes(:character => [:battles,:battle_records])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment