On Sun, Feb 19, 2006 at 02:25:22AM +0900, Dae San Hwang wrote:
> Hi,
> 
> As I understand, composite primary keys aren't supported in ActiveRecord yet. 
>  May I ask if there are plans for this feature?  
> Better yet, if this feature is under development, how's the progress going?
> 
> I'm not trying to use legacy databases.  I tend to think that using multiple 
> integer column id's (composite primary key) are often 
> natural way to implement one-to-many relationships, for things like "forum 
> replies".  For example, ID for the third comment of forum 
> topic #87 should be (87, 3) not (87, 1074), format being (topic_id, reply_id).
> 
> Currently, I'm trying to work around this by using 'TopicReply.find(:fist, 
> conditions => ["topic_id=? AND id=?", 87, 3]' instead of 
> 'TopicReply.find(1074)'.  However, I haven't figured out yet how to save such 
> objects..
> 
> Any comment will be greatly appreciated.
> 
> Thanks,
> 
> daesan
> _______________________________________________
> Rails-core mailing list
> Rails-core@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-core

I hear that AR lacks support for composite keys on nearly a daily basis now.  
This
always strikes me at odds with reality as we utilize composite foreign keys on 
a 
daily basis in many of our applications.  The only sensible place I've found to 
utilize composite foreign keys in a relation exists in join tables, which 
generally
are not (but can easily be) mapped to an AR model for finds.  It's unlikely that
for Inserts on the TopicReply model you would not already have a Topic or Reply 
instance available to use the common @topic.replies << @reply or 
@topic.create_reply(Reply.create(params[:reply])).  The composite foreign key
is validated on save from both the @topic.replies << @reply and on the DB 
itself (if supported).
On one-to-many, the need for composite keys simply doesn't exist, and many 
methodologies
exist to work around the link and large integer id issue, routes being my 
preferred way to implement the pretty links.
-- 
TJ Vanderpoel GCIA,GCIH
[EMAIL PROTECTED]

Attachment: pgpQV8tQk4jb6.pgp
Description: PGP signature

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

Reply via email to