Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8919285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:58:51+00:00 2026-06-15T05:58:51+00:00

I have a Team object and a Game object. A Game is supposed to

  • 0

I have a Team object and a Game object.

A Game is supposed to have one winner which is a Team
A Team can be the winner of multiple Games

How can I structure this correctly? I’m using Mongoid

This is what I came up with so far…

class Game
  include Mongoid::Document
  include Mongoid::Timestamps
  has_one :winner, :class_name=>Team
end

class Team
  include Mongoid::Document
  include Mongoid::Timestamps
  has_and_belongs_to_many :games_won, :class_name=>"Game", :inverse_of => :Game 
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:58:52+00:00Added an answer on June 15, 2026 at 5:58 am

    Consider abstracting the win out into its own class, so that:

    class Game
      has_one :win
    end
    
    class Team
      has_many :wins
    end
    
    class Win
      belongs_to :game
      belongs_to :team
    end
    

    This makes the structure more logical, makes the code simpler, and has other advantages for situations where you might want to start working with wins as a separate resource for other reasons.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a team set up on bitbucket with multiple users, and I'm using
my team have built many tools for our project using win forms and Visual
We have a team that built an agent in Mono using MonoDevelop on Mac
So I have this model Game that has an Awayteam and Hometeam field. Now
this is my first post to stack overflow! I'm using SlimDX for a game
I have been using an Object-Oriented MVC architecture for a web project, and all
I have a team leader object, and have lot of team members object own
Imagine you have two entities, Player and Team , where players can be on
Say I have a model like: class Team(models.Model): name = models.CharField(max_length=20) class Game(models.Model): title
Team, I have build a VB.Net windows application which does uploads data into database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.