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.
Cd8c9864d88bcafc164d8fdb820cc451?d=identicon&s=25 Chris (Guest)
on 2005-11-19 19: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
Cd8c9864d88bcafc164d8fdb820cc451?d=identicon&s=25 Chris <evilgeenius@gmail.com> (Guest)
on 2005-11-19 19:43
Sorry i meant "has_one" not "has_a".
Db303dc84d03a992b33cd3ac978f89ae?d=identicon&s=25 rails (Guest)
on 2005-11-19 19: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
832cf770881fdde1e604873ac425d89b?d=identicon&s=25 Gabriel Boys (Guest)
on 2005-12-07 00: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.