This should work for you
class Origin < ActiveRecord::Base
has_many :leads, :foreign_key =>
''''howdidyouhear''''
end
class Lead < ActiveRecord::Base
belongs_to :origin, :foreign_key => ''howdidyouhear''
end
Regards,
Jatinder
On 10/17/06, Ike <rvince99-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org>
wrote:>
>
> I''m confused on ActiveRecord, particularly where integration to
legacy
> DBs are concerned. I am hoping someone can point me to a reference that
> explains foreign_key and association_foreign_key for me.
>
> If I have a legacy MySQL DB with two tables specifid below, wherein I
> have
> a table, ''leads'' which contains an index to
''origins'' such that
> leads.howdidyouhear=origins.id
>
> 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. I am mapping it as follows
> (I am
> not certain this is correct, can someone please confirm? Does someone
> have a link that explains this better to me? Thanks, Ike) :
>
> class Origin < ActiveRecord::Base
> has_many :leads, :foreign_key => ''originname''
> end
>
> class Lead < ActiveRecord::Base
> belongs_to :origin, :foreign_key => ''howdidyouhear''
> end
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---