[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Active Record and different field names

JZ

4/2/2005 8:51:00 PM

I have several mysql tables and I would like to start using Active Record
instead of direct sql queries. The problem is I cannot find how to join to
these tables when they have different names for their primary keys. As i
understand AR and Rails assumes "id" as a field name for primary keys. What
if I have totally different names for fields? How to join to such tables
using AR? I couldn't find the answer in API for AR.

--
JZ
1 Answer

David Heinemeier Hansson

4/2/2005 9:01:00 PM

0

> As i understand AR and Rails assumes "id" as a field name for primary
> keys. What
> if I have totally different names for fields? How to join to such
> tables
> using AR? I couldn't find the answer in API for AR.

You can specify a different primary key than id using set_primary_key,
like:

class Person < ActiveRecord::Base
set_primary_key "iPeopleId"
end

Similar construct for a unguessable table name with set_table_name.
--
David Heinemeier Hansson,
http://www.basec... -- Web-based Project Management
http://www.rubyon... -- Web-application framework for Ruby
http://www.loudthi... -- Broadcasting Brain