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|
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 )
Will it be hard to create an association that can handle this?
Thanks in advance for any advice you can give me,