Created
April 11, 2012 08:40
-
-
Save ukstudio/2357972 to your computer and use it in GitHub Desktop.
battle.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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