我很新,在学习数据库的东西以及Rails的过程中。现在我有以下声明:
def tournaments_played
@tournaments_played = Tournament.count
end
使用这些模型:
class User < ActiveRecord::Base
has_one :profile, dependent: :destroy
has_many :tournaments, through: :profile
class Profile < ActiveRecord::Base
belongs_to :user, class_name: "User"
has_many :tournaments
class Tournament < ActiveRecord::Base
belongs_to :profile
belongs_to :user
显然,tournaments_played正在返回每条记录的计数。我只想要那个用户的锦标赛。如果需要,我可以粘贴方案!