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

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.
1f840b624a948a3f39299af25620121b?d=identicon&s=25 Ross Dawson (Guest)
on 2006-05-11 01: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.

Ross
Cfda8d3a956b6bf4b73f8fc2132da051?d=identicon&s=25 Kenneth Liu (Guest)
on 2006-05-11 02: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.

Ken
This topic is locked and can not be replied to.