Created
July 8, 2014 13:55
-
-
Save hxx/dc95849d3d3079ed9a29 to your computer and use it in GitHub Desktop.
has_many :through
This file contains hidden or 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 Play < ActiveRecord::Base | |
# 先告诉model我们在体育协会有很多笔资料 | |
has_many :sports_associations | |
# 这些资料是要拿来判断这个球员有参与多少球队 | |
has_many :teams, :through => :sports_associations | |
end |
This file contains hidden or 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 SportsAssociations < ActiveRecord::Base | |
# 体育协会要对球员和球队负责,所以体育球队belongs_to球员和球队 | |
belongs_to :team | |
belongs_to :player | |
end |
This file contains hidden or 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 Team < ActiveRecord::Base | |
# 先告诉model我们在体育协会有很多笔资料 | |
has_many :sports_associations | |
# 这些资料是要拿来判断这个球队有多少球员 | |
has_many :players, :through => :sports_associations | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment