Ike
10/17/2006 1:06:00 AM
I have a legacy MySQL DB which is ALMOST Rails-ready, i.e. the table names
are correct, they all have a unique integer index 'id' etc. However, I have
a table, 'leads' which contains an index to 'origins' such that
leads.howdidyouhear=origins.id. If this were truly Rails-ready, the
leads.howdidyouhear would be leads.origins_id, but, I cannot rename it. The
db's look like this:
CREATE TABLE `origins` (
`id` int(11) NOT NULL auto_increment,
`originname` varchar(60) NOT NULL default ''
)
CREATE TABLE `leads` (
`id` int(11) NOT NULL auto_increment,
`howdidyouhear` int(11) NOT NULL default '0',
`amount` double NOT NULL default '0',
`homeplan` int(3) NOT NULL default '0'
)
My problem is mapping this in active record. When I map it as follows (I am
not certain this is correct, can someone please confirm?) :
class Origin < ActiveRecord::Base
has_many :leads, :foreign_key => 'originname'
end
class Lead < ActiveRecord::Base
belongs_to :origin, :foreign_key => 'howdidyouhear'
end
However, when I create:
class LeadController < ApplicationController
scaffold :lead
end
The scaffolding for /lead still shows the integer for `howdidyouhear`.
Shouldn't it show the originname String for the howdidyouhear int when it
displays?
Thanks, Ike