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

  • Home
  • SEARCH
  • 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 561427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:26:56+00:00 2026-05-13T12:26:56+00:00

I’m building my first Rail App and are beginning to setup my database. I

  • 0

I’m building my first Rail App and are beginning to setup my database. I have a simpel Users table containg name, e-mail (login), password and so on.

The site lets the users bet each other (with monopoly money), so I need to add information about the users current winnings and other delicate matters to the database.

Question: Should I place these information in the Users table or should I create an Account Table and insert the information there. I’m lacking the knowledge to see if it should raise any security issues to insert the information in the Users table.

Kind regards

Kenneth
Denmark

  • 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-13T12:26:56+00:00Added an answer on May 13, 2026 at 12:26 pm

    From a transactional point of view, it is much better to have subsidiary records that track operations than to modify a single record in place.

    For instance, if you are having a system where users can place “bets”, then it stands to reason there would be some kind of Bet class that defines a bet between two people. As users create bets, the associated list will grow. In Rails parlance, it looks like this:

    class User < ActiveRecord::Base
      has_many :bets
      has_many :bet_pools,
        :through => :bets
    end
    
    class Bet < ActiveRecord::Base
      belongs_to :user
      belongs_to :bet_pool
    end
    
    class BetPool < ActiveRecord::Base
      has_many :bets
      belongs_to :winning_bet
      belongs_to :winning_user,
        :class_name => 'User',
        :through :winning_bet,
        :source => :user
    end
    

    The amount of each bet is stored in the Bet record, and the BetPool represents the aggregate bets made towards a particular wager, though you may have a different term for such a thing.

    A winner can be designated by assigning the bet_pool.winning_user association if and when the bets are settled.

    If you want to know a user’s “winning record”, then it is as easy as tabulating all the betting pools that they’ve won and adding up the amounts.

    The reason you don’t want to be constantly adjusting some property on the User record is because two independent processes may want to tweak that value and you can end up with a race condition if the SQL is not implemented properly. For instance, a user might place a bet and win a bet in a very short period of time.

    If a user started with $1000 and two operations occur simultaneously, then this could happen:

    # Process A intending to add $500
    user.balance = user.balance + 500
    user.save
    
    # Process B intending to deduct $100
    user.balance = user.balance - 100
    user.save
    

    Done sequentially you’d expect the balance to go from 1000 to 1500 and then down to 1400, but the second process started with the original value of 1000 when it loaded, then adjusted to 900 and saved, over-writing the result of the first.

    There are methods like increment and decrement for ActiveRecord that can help with this sort of thing, but the best results are achieved by simply tabulating as required.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.