I'm trying to get the following Mongoid relationships to work, but the game field of each team is an empty array. Is this not a valid relational model? Do I need to split up games, i.e. home_games and away_games?
class Team
include Mongoid::Document
has_many :games, :autosave => true
end
class Game
include Mongoid::Document
belongs_to :home_team, :class_name => "Team", :inverse_of => :games
belongs_to :away_team, :class_name => "Team", :inverse_of => :games
end
I dont think so there is a straight way to do this, may be you workaround by
so now you can use it like
and
abd you can get the total count by
Hope this helps