Forum: Ruby on Rails validates_associated

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.
Jake J. (Guest)
on 2005-11-15 07:18
I have an db table that associates two things from the same table.

people_alt_people
-----------------
person_id
alt_person_id

So my ActiveRecord looks like:

class PeopleAltPerson < ActiveRecord::Base
  belongs_to :person
  belongs_to :altperson, :class_name => 'Person', :foreign_key =>
'alt_person_id'

  validates_presence_of  :person
  validates_associated   :person
  validates_presence_of  :altperson    # HERE?
  validates_associated   :altperson    # HERE?
end

It's the last two lines I'm asking about.  Can the validates_associated
macro be used in this situation?  i.e. where a table has two references
to the same table.

  Jake
This topic is locked and can not be replied to.