# Trying to Not Repeat Myself...a question concerning storing dates

**URL:** <https://www.ruby-forum.com/t/trying-to-not-repeat-myself-a-question-concerning-storing-dates/138618>\
**Category:** Rails\
**Created:** [May 25, 2008, 11:45pm UTC](https://www.ruby-forum.com/t/trying-to-not-repeat-myself-a-question-concerning-storing-dates/138618 "2008-05-25T23:45:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathaniel\_Riethmann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ecb155/32.png) [@Nathaniel\_Riethmann](https://www.ruby-forum.com/u/Nathaniel_Riethmann)\
**Post date:** [May 25, 2008, 11:45pm UTC](https://www.ruby-forum.com/t/trying-to-not-repeat-myself-a-question-concerning-storing-dates/138618/1 "2008-05-25T23:45:36Z")

</div>

I’m working on a project that requires tracking the sales data for six  
stores (although that number may increase). Each store is open Monday  
through Saturday and only four specific holidays are observed. With  
that said, I’m wondering, what is the best way to store the sales data  
for each location?

One approach would be to simply use a ‘stores’ table and a  
‘sales\_figures’ table with each row in the latter containing a  
store\_id, the date, and the required sales figures. But this feels  
repetitious to me as the same date will be stored six times (once per  
store per day).

Would I be better served adding a ‘sales\_dates’ table (and perhaps a  
‘holidays’ table), thereby reducing the number of times a given date  
is stored to 1, and doing some relationship business in the ‘figures’  
table (using ‘store\_id’ and ‘sales\_date\_id’)? Or am I doing what I  
always do and thinking about this one too hard? I’m just trying to  
stay agile!

Thanks in advance for any input.

Nate

---

<div class="post-metadata">

**Author:** ![Nathaniel\_Riethmann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ecb155/32.png) [@Nathaniel\_Riethmann](https://www.ruby-forum.com/u/Nathaniel_Riethmann)\
**Post date:** [May 26, 2008, 12:15am UTC](https://www.ruby-forum.com/t/trying-to-not-repeat-myself-a-question-concerning-storing-dates/138618/2 "2008-05-26T00:15:37Z")

</div>

On Sun, May 25, 2008 at 6:48 PM, Nathaniel Riethmann  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> store per day).
> 
> Would I be better served adding a ‘sales\_dates’ table (and perhaps a  
> ‘holidays’ table), thereby reducing the number of times a given date  
> is stored to 1, and doing some relationship business in the ‘figures’  
> table (using ‘store\_id’ and ‘sales\_date\_id’)?

Sounds too complicated to me, and you’d end up repeating the  
sales\_date\_id in a similar manner anyway.

I’d use the first option because it is straighforward and represents  
the data in a natural way: this store sold this on such day. Thus the  
involved code will equally be easy as far as this choice is concerned.

– fxn

---

<div class="post-metadata">

**Author:** ![Nathaniel\_Riethmann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ecb155/32.png) [@Nathaniel\_Riethmann](https://www.ruby-forum.com/u/Nathaniel_Riethmann)\
**Post date:** [May 26, 2008, 4:44am UTC](https://www.ruby-forum.com/t/trying-to-not-repeat-myself-a-question-concerning-storing-dates/138618/3 "2008-05-26T04:44:47Z")

</div>

Not sure what the project’s intention is. If it is just an aggregate  
of total sales figures by date, then it appears you only need a table  
called sales\_aggregate, and another table called stores to store  
details about each store.

Seems unlikely though. Aren’t you getting more granular data, like  
actual sales. If that is the case then your db structure should  
include orders, order\_lines, customers, stores, products. Then you are  
in a better position to report on any of thos. The date or the sale is  
stored in the order, and possibly you will need to cache at the order  
level the period\_id, which would be in another table to symbolize the  
most granular timeframe you would report in, probably month\_yr.
