A vanilla polymorphic belongs_to association allows different
association instances to have targets in different classes. I want to
do a has_many association where different association instances have
different foreign_keys. Is such a thing possible?
My schema looks like
create_table "people", :force => true do |t|
t.string "name"
t.string "sex"
t.integer "father_id"
t.integer "mother_id"
end
and my model I want something like:
class Person < ActiveRecord::Base
belongs_to :father, :class_name => "Person"
belongs_to :mother, :class_name => "Person"
#I want something like this is invalid syntax
has_many :children, :class_name => "Person", :foreign_key => ( sex
== 'M' ? :father_id : :mother_id )
end
Will it be hard to create an association that can handle this?
Thanks in advance for any advice you can give me,
Joe
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.