RE: Re: Composite Key

Ron DiFrango
Fri, 14 Oct 2005 19:39:32 -0000

Bill,

My intention here is not to start a flame war, but the issue of composite keys
is one limitation that has given me some pause about RoR.  I will say, it has
made me look back over my data model [which I control to a large degree in one
of my projects] and see if my composite keys make sense and a truly necessary.
My initial reaction was yes they were absolutley necessary, but after a critical
look all but the following scenario could fall under the RoR way execept my
"Rules" table.

Here is the situation, I have a table called selections which has an identity
column called selections_id.  On this table there is also a column that tells me
whether or not the pricng for selection is rule based.  If it is, then I have
code that typically says, I have a group of selections that together in some
combintation make up the price for the selection.  On the rules table I have 3
ID columns which are actually foreign keys back into the selections table.
Since they are unique combinations, I just utilize all 3 of them as my primary
key on the table.

Now, I could add a column that is an ID column to the table, but in my mind it
is a waste of space because it is nothing more than a placeholder just to
satisfy RoR.

I will say that in most if not all the enterprise app I have worked on we have
had Composite Keys that in my opinion were absolutely necessary and fall under
this category where you are combining keys from either multiple tables or there
unique combinations yeilded something different.  I think for RoR to truly
succeed, it needs built-in support for not only Composite Keys, but quite
possibly those that are character based as well.

With that said, I am in the process of attempting a conversion from a J2EE
architecture [JSP/SOFIA - Web framework/Hibernate/EJB, etc.] to RoR.  Wish me
luck!

Ron

	-----Original Message-----
	From: Bill Lazar [mailto:blazar@gmail.com]
	Sent: Fri 10/14/2005 2:29 PM
	To: rails@lists.rubyonrails.org
	Cc:
	Subject: [Rails] Re: Composite Key



	Háber János <boci@...> writes:
	> Bill Lazar írta:
	> >Háber János <boci <at> ...> writes:
	> >
	> >>I want to create  a multi language table because
	> >>AR not support composite primary keys... Now I have 2 table words
with one
	> >>column (id) and localized_word with lang_id, word_id ant the
localized text.
	> >
	> >Probably "Using Gettext To Translate Your Rails Application"
is a
	> >good place to look for the Rails-normal way of handling this common
issue.
	> >
	> That's ok, but I want to allow the user modify/add the words. The
words
	> table id is a many table foreign key. Example I have a property table
	> where the user can add new propertyes , these properties is
	> multilangual. So that's the reason why I can't use gettext. Ohh
and user
	> can add new languages for their page.

	Fair enough. I would disagree with the need for a composite key, regardless of
	RoR or implementation language, and still use just id as PK with indexes on the
	fields you suggest make up the 'functional' key. Just filter at runtime
based on
	the user's settings. Not sure why this bothers you though, so no hard
feelings
	and perhaps I'm not the person to answer for your specific needs.

	_______________________________________________
	Rails mailing list
	Rails@lists.rubyonrails.org
	http://lists.rubyonrails.org/mailman/listinfo/rails




_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org