Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Active Record and different field names

1 view
Skip to first unread message

JZ

unread,
Apr 2, 2005, 3:51:08 PM4/2/05
to
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

David Heinemeier Hansson

unread,
Apr 2, 2005, 4:01:04 PM4/2/05
to
> 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.basecamphq.com/ -- Web-based Project Management
http://www.rubyonrails.org/ -- Web-application framework for Ruby
http://www.loudthinking.com/ -- Broadcasting Brain

0 new messages