我是設計足球統計應用程序。我堅持存儲遊戲(匹配)結果。 我有團隊對象和遊戲對象。首先讓遊戲模型看起來像如何在MongoDB中存儲足球隊,比賽和比分
class Game
include Mongoid::Document
belongs_to :team_1, class_name: "Team"
belongs_to :team_2, class_name: "Team"
field :score_1, type: Integer
field :score_2, type: Integer
但它不允許我找到所有的團隊遊戲。 接下來,我決定做這樣的事情:
class Game
include Mongoid::Document
has_and_belongs_to_many :teams
field :scores, type: Array
不過貌似隊爲了不匹配分數和長相醜陋。 接下來我創建了存儲團隊的模型分數和它的分數,而遊戲模型有很多分數,但這比以前更難看。
「但它不允許我找到所有的團隊比賽」---爲什麼不呢? –