Active Record and different field names

J

JZ

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.
 
D

David Heinemeier Hansson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top