I am building my first Rail Application and therefore are starting to setup my database. I've got a simpel Customers table containg title, e-mail (login), password and so forth.

The website allows the customers wager one another (with monopoly money), so I have to add details about the customers current winnings along with other delicate matters towards the database.

Question: Must I place these information within the Customers table or must i create a free account Table and place the data there. I am missing the understanding to ascertain if it will raise any security issues to place the data within the Customers table.

Xox

Kenneth
Denmark

Their actions really are a different entity then your actual user themselves. Keep user information for example profile info in a single table. Other organizations ought to be seperated. Would you like to seperate that into another table and make up a foreign key to the customers table to find out which row within this accounts table goes towards the user.

From the transactional perspective, it is way better to possess subsidiary records that track procedures rather than modify just one record in position.

For example, if you're getting a method where customers are able to place "bets", it makes sense there'd be some type of Wager class that defines a wager between a couple. As customers create bets, the connected list will grow. In Rails parlance, it appears such as 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 quantity of each wager is saved within the Wager record, and also the BetPool signifies the aggregate bets made towards a specific wager, though you might have another term for this type of factor.

A champion could be designated by setting the wager_pool.winning_user association assuming the bets are settled.

If you wish to know a user's "winning record", then its as simple as tabulating all of the betting pools that they have won and accumulated the amounts.

The main reason you won't want to be constantly modifying some property around the User record happens because two independent processes might want to tweak that value and you will finish track of a race condition when the SQL isn't implemented correctly. For example, a person might place a wager and win a wager in an exceedingly short time.

If your user began with $1000 and 2 procedures occur concurrently, than the might 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 total amount to visit from 1000 to 1500 after which lower to 1400, however the second process began using the original worth of 1000 if this loaded, then modified to 900 and saved, over-writing caused by the very first.

You will find techniques like increment and decrement for ActiveRecord that will help with this particular kind of factor, but the greatest results are accomplished simply by tabulating as needed.