Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store "same as" data?

I've got one model with 3 addresses: pickup, dropoff, and billing. I figure the billing address will usually be either the pickup or drop-off address, so from a UI perspective, I should have a "same as" option. But from a DB perspective, should I save the "same as" field, or should I duplicate the data?

like image 926
mpen Avatar asked Oct 13 '10 20:10

mpen


1 Answers

You should have the same Id of a row from an Address table in two different columns, PickUp and DropOff. This way, you do not duplicate the address, do not use some sentinel address, and can easily query to see if the PickUp address is the same as the DropOff. If one of these changes in the future, you can always modify the Id value stored in its respective column to a new address.

like image 180
Michael Goldshteyn Avatar answered Sep 24 '22 14:09

Michael Goldshteyn