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 4015986
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:41:07+00:00 2026-05-20T09:41:07+00:00

I’m trying to make a simple tournament system, and now I’ve come to another

  • 0

I’m trying to make a simple tournament system, and now I’ve come to another wall…
I have a Table named Teams – Each Team can participate in multiple matches.

I’ve thought about having a table named Matches which have 4 columns:

  • ID => Identifier
  • Team1ID => Reference to ID in Teams
  • Team2ID => Reference to ID in Teams
  • WinnerID => Same value as either Team1ID or Team2ID

WinnerID will then have a sql trigger that checks whether its the same value as Team1ID or Team2ID… If not it will rollback the transaction.

This approach seemed perfect in the start, until I realized that it broke several “best practice” rules, including the “repository per aggregate root” because it would require me to do:

Team myTeam1 = ... Get team1 ...
Team myTeam2 = ... Get team2 ...

Match myMatch = new Match { Team1 = myteam1, Team2 = myteam2; }

which is wrong since the Match entity is defined as a “child entity” for the Team entity, and should only be added through the Team entity.

Any suggestions about how to design my database properly to fit my needs?

  • 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-05-20T09:41:08+00:00Added an answer on May 20, 2026 at 9:41 am

    As far as the trigger, I would just use some constraints.

    (Team1ID <> Team2ID)
    AND
    (WinnerID IS NULL OR Team1ID = WinnerID OR Team2ID = WinnerID)
    

    probably all in one constraint.

    As far as the domain model, I would not have thought you add a match through a team, but perhaps through a tournament instance: Match = Tournament.NewMatch(Team1, Team2) ;

    Conceivably, there would be higher order tournament rules, like rounds, eliminations, etc.

    Since it sounds like your Teams know their Cup, then to create a Team or retrieve it from the database, it would go through the Cup: Cup.NewTeam(TeamName) or Cup.LoadTeam(TeamID). It would still make sense then for Cup.NewMatch, since you certainly wouldn’t want to have a match between teams in different Cups.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a

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.