An address table is one good idea, but keep in mind that if you want to
meet your first goal of keeping the addresses used on invoices, you’d
have to save any “edited” address as a new address entry and retain
fields for marking which ones are “current”, maybe one for “which” of
the users’ saved addresses this is (home, work, gramdma,etc.), and
another for the version, so that an order going to Mary’s home address
in April stays linked to the April home address.
A much simpler but less flexible solution is to have address fields in
the order itself and copy them from the User table at the time the order
is saved. This way addresses and even users can be modified and deleted
to your heart’s content, but the address info stays with the record of
The disadvantage to the simpler approach is that it doesn’t offer a
clean way to generate a report on all the orders shipped to a given
address, for instance. But then, plenty of e-commerce sites get by just
fine without such things. It’s all a matter of how much complexity you
reasonably expect to use.
Ryan L. wrote:
I am begining the design of an order management system, and had a few
about the database design. For example: I have a customers table and an
table, with a one to many relationship. Now if i change the customers
after the order has been created, it will be updated in any of the past
and I do not wish this to happen. Is the best way to deal with this to
customers information in the order table, or is there an easy way to set
sort of versioning system for the customer within rails?