Nathaniel Riethmann
2008-May-25 16:48 UTC
Trying to Not Repeat Myself...a question concerning storing dates
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Xavier Noria
2008-May-25 22:14 UTC
Re: Trying to Not Repeat Myself...a question concerning storing dates
On Sun, May 25, 2008 at 6:48 PM, Nathaniel Riethmann <nriethmann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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'')?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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
alberto
2008-May-26 02:42 UTC
Re: Trying to Not Repeat Myself...a question concerning storing dates
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---