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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:59:31+00:00 2026-05-16T17:59:31+00:00

I am planning a relational database to store poker game data (like what would

  • 0

I am planning a relational database to store poker game data (like what would be included in the hand histories). I would like help figuring out how to design the associations. It seems like there should be 4 models: Game, Hand, Player, and Action (single action of a given player, like raise, fold, call). Let me lay out what I have:

class Game < ActiveRecord::Base
  has_many :hands
  has_many :actions
  has_and_belongs_to_many :players
end

class Hand < ActiveRecord::Base
  has_many :actions
  belongs_to :game
  has_and_belongs_to_many :players
end

class Action < ActiveRecord::Base
  belongs_to :game
  belongs_to :hand
  belongs_to :player
end

class Player < ActiveRecord::Base
  has_and_belongs_to_many :games
  has_and_belongs_to_many :hands
  has_many :actions
end

Does this make sense?

  • 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-16T17:59:32+00:00Added an answer on May 16, 2026 at 5:59 pm

    If you’re planning to use has_and_belongs_to_many, you should probably switch to using has_many ..., :through as it’s much easier to manage. You already have an Action model that does what you need without having to create some join tables:

    class Game < ActiveRecord::Base
      has_many :hands
    end
    
    class Hand < ActiveRecord::Base
      has_many :actions
      belongs_to :game
    
      has_many :players,
        :through => :actions,
        :source => :player
    end
    
    class Action < ActiveRecord::Base
      belongs_to :game
      belongs_to :hand
      belongs_to :player
    end
    
    class Player < ActiveRecord::Base
      has_many :actions
      has_many :played_games,
        :through => :actions,
        :as => :game
      has_many :played_hands,
        :through => :actions,
        :as => :hand
    end
    

    Generally, the fewer tables you have involved in your queries, the faster they will run. Involving any kind of JOIN is going to lead to unpredictable query performance.

    Be sure to index your tables carefully, and use the EXAMINE statement to ensure you’re hitting indexes when using them. Table scans will be extremely painful if you load this up with millions of records, and that doesn’t take long in games like this as a single hand involves dozens of actions and it’s typical to play dozens of hands every hour.

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

Sidebar

Related Questions

I'm currently planning an application that does work on an object relational database. The
I planning on reading profile data from a xml file in JSP. Now i
I am planning to schedule a job on one my database and which basically
I am planning for an application of time-table generation. I wanted the data such
We are planning a SAAS application. Now we are at the database point. A
Im planning to make my next app 3.0 only (with Core Data). Does anyone
I'm planning on using Apache torque as my object-relational mapper (ORM), and I was
When planning and prioritizing what is to be included in a release, do you
Im planning to use the Entities generated by the EF (POCO) in sending data
Im planning on using ASIHTTP to handle some long file downloads/installs and I'd like

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.