Forum: Ruby on Rails Application and Database Design

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3b87f1ad86f6a44241832314873e8d54?d=identicon&s=25 Ryan Lundie (Guest)
on 2006-04-14 17:20
(Received via mailing list)
Hi,

I am begining the design of an order management system, and had a few
questions
about the database design. For example: I have a customers table and an
orders
table, with a one to many relationship. Now if i change the customers
address
after the order has been created, it will be updated in any of the past
orders,
and I do not wish this to happen. Is the best way to deal with this to
store the
customers information in the order table, or is there an easy way to set
up some
sort of versioning system for the customer within rails?

Thanks,
Ryan
E9fd0a26f21517b453c368d0fb48bc12?d=identicon&s=25 Benjamin Orchard (Guest)
on 2006-04-14 17:39
(Received via mailing list)
I think that the easiest way to do this is create an addresses table
with relationships to both the customers and the orders.  It would have
many addresses for both customers and orders (one to many relations).
This is how you set up a versioning system.  It also requires that you
put into the addresses table some indicator of a preferred address for
the customer so that it is easy to know which is the default.

Others may have some other ideas.

Ben Orchard
B780ee0ee1480454a85df58536702f63?d=identicon&s=25 Alder Green (Guest)
on 2006-04-14 17:42
(Received via mailing list)
On 4/14/06, Ryan Lundie <ryan@b2blogic.net> wrote:
> Thanks,
> Ryan
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

Hi Ryan

>From your description, I think the simplest, best solution would be to
"stamp" the current customer address into any order created. That way
the address "stays" with the order, independtly of the client. You can
however retrieve all past orders of the client, and hence all his past
addresses, so you in effect get all the benefits of versioning without
the costs.

Regards,
Alder
34f5b045aec62235c17458650ea75353?d=identicon&s=25 Steve Koppelman (hatless)
on 2006-04-14 18:11
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 order.

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 Lundie wrote:
> Hi,
>
> I am begining the design of an order management system, and had a few
> questions
> about the database design. For example: I have a customers table and an
> orders
> table, with a one to many relationship. Now if i change the customers
> address
> after the order has been created, it will be updated in any of the past
> orders,
> and I do not wish this to happen. Is the best way to deal with this to
> store the
> customers information in the order table, or is there an easy way to set
> up some
> sort of versioning system for the customer within rails?
>
> Thanks,
> Ryan
9f0f89bbd9e1ecfbaab6584e429b7a2f?d=identicon&s=25 Josh Susser (jsusser)
on 2006-04-14 18:24
Ryan Lundie wrote:
> I am begining the design of an order management system, and had a few
> questions
> about the database design. For example: I have a customers table and an
> orders
> table, with a one to many relationship. Now if i change the customers
> address
> after the order has been created, it will be updated in any of the past
> orders,
> and I do not wish this to happen. Is the best way to deal with this to
> store the
> customers information in the order table, or is there an easy way to set
> up some
> sort of versioning system for the customer within rails?

Check out the acts_as_versioned plugin

--
Josh Susser
http://blog.hasmanythrough.com
This topic is locked and can not be replied to.