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 planning on creating a game that contains a landscape with objects on it.
I'm planning to write a program in Ruby to analyse some data which has
We're currently planning a new API for an application and debating the various data
One thing I have continually found very confusing about using an object database like
I am current in planning on creating a big database (2+ million rows) with
I'm planning to use Ogre3d for 3d rendering to make a game prototype. Wanted
I am planning to make an application like cPanel/WHM in perl since i never
I'm planning a chat-like web application, where whenever one user posts something, all other
I am planning to build an ASP.NET survey platform, that would also provide a
I'm in the planning and learning stages of building a facebook game. For the

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.