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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:28:12+00:00 2026-05-22T12:28:12+00:00

I would appreciate some advice on how to structure a database for the following

  • 0

I would appreciate some advice on how to structure a database for the following scenario:

I’m using Ruby on Rails, and so I have the following tables:

  • Products
  • Salespeople
  • Stores

Products are manufactured in batches, so each product item has a Batch code, so I think I will also need a table of batches, which refers to a product type.

  • Batch

In the real world, Salespeople take Product items (from a specific Batch) and in due course issue it to a Store. Importantly, Batches are large, and may be spread across many Salespeople, and subsequently, Stores.

At some future date, I would like to run the following reports:

  • Show all Batches of a Product issued to a specific Store.
  • Show all Batches held by a Salesperson (i.e. not yet sold).

Now, I’m assuming I need to build a table of Transactions, something like,

  • Transaction
    • salesperson_id
    • batch_id (through which the product can be determined)
    • store_id
    • typeOfTransaction (whether the Salesperson has obtained some stock, or sold some stock)
    • quantity

By dynamically running through a table of Transaction records, I can could derive the above reports. However, this seems inefficient and, over time, increasingly slow.

My question is: what is the best way to keep track of transactions like this, preferably without requiring dynamic processing of all transactions to derive total items from a batch given to a given store.

I don’t believe I can just keep a central record of stock as Product comes in Batches, and Batches are distributed by Salepeople across Stores.

Thank you.

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

    My question is: what is the best way to keep track of transactions like this, preferably without requiring dynamic processing of all transactions to derive total items from a batch given to a given store.

    I don’t believe I can just keep a central record of stock as Product comes in Batches, and Batches are distributed by Salepeople across Stores.

    Believe it. 🙂

    In my experience, the only correct way to store this kind of stuff, is to break it down to something akin to T-leger accounting, i.e. debit/credit with a chart of accounts. It requires dynamic processing to derive totals as you’ve found out, but anything short of that will lead to tricky queries when dealing with reports and audit trails.

    You can speed things up significantly, by maintaining partial or complete aggregate balances using triggers (e.g. monthly stock movements per store). This will reduce the number of rows you need to sum when running larger queries. Which of these you’ll want to maintain will depend on your app and your reporting requirements.

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

Sidebar

Related Questions

I would appreciate some guidance on modelling services and operations in WCF. I have
I have a design issue that I would appreciate some input on. I would
I have an interesting problem and would appreciate your thoughts for the best solution.
I've hit a blank here and would appreciate a kick start. I have two
I'm new to regular expressions and would appreciate your help. I'm trying to put
I've been researching memory mapped files for a project and would appreciate any thoughts
My code works (yeah!) which sends json to a server.. would appreciate any thoughts
I would really appreciate any suggestions, no matter how simple or complex, to help
Assuming such a query exists, I would greatly appreciate the help. I'm trying to
Folks, We have been using OpenXml APIs found in System.IO.Packaging for creating a package

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.