Forum: Ruby on Rails RE: Re: Re: how best to implement lookup table?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ross D. (Guest)
on 2006-05-11 03:59
(Received via mailing list)
Best reason to use ids rather than some magic code is there is a
posibility that the code may change somewhere down the track.

e.g. if you linked order lines to an order by the order number what
happens if the customer required a change to the exisiting order numbers
(say adding a prefix or suffix).  Youd have to change the order records
and the order line records (after removing contraints and then
reinstating them after the change).  Using ids (something not related to
the business models) you are free to change the business rules without
affecting the integrity of you data.

My rule of thumb is to always use integer (32/64 bit) ids to join
related tables, and this id should only be used for the join (not
containing some magic business model value).  It's a RDBMS construct not
a business construct.

If you were using an OODB then you wouldn't have the id, the
relationship would be defined through aggreagation.

Kenneth L. (Guest)
on 2006-05-11 04:23
(Received via mailing list)
That sounds good enough for me.  I understand that this is the
justification for using the rails "id" column in general, but thought
for a moment that it didn't apply in this case.  I was wrong.

Appreciate the help.  Thanks.

This topic is locked and can not be replied to.