Forum: Ruby on Rails How to get two "has_a" relationships to the same table?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chris (Guest)
on 2005-11-19 20:39
I have an audit table with fields auditor_id and manager_id that both
link to the people table:

AUDIT:
id
name
datecreated
auditor_id
manager_id

PEOPLE:
id
name

I have no idea how to link both fields from audit to people?? any
ideas??
I'm pulling my hair out trying to figure this out, please help!!

I know that if it were just one field then i'd call the field person_id.

Thanks,
Chris
Chris <> (Guest)
on 2005-11-19 20:43
Sorry i meant "has_one" not "has_a".
rails (Guest)
on 2005-11-19 20:57
(Received via mailing list)
You probably want something like this:

class Audit < ActiveRecord::Base
   belongs_to :auditor, :class_name => 'Person', :foreign_key =>
'auditor_id'
   belongs_to :manager, :class_name => 'Person', :foreign_key =>
'manager_id'
end
Gabriel Boys (Guest)
on 2005-12-07 01:55
Awesome I was trying to figure this exact same thing out and this worked
perfectly, thanks.
This topic is locked and can not be replied to.