4

I've been banging my head for a while on this one. The problem comes in when saving both a new referral (the parent object) and an appointment(child) at the same time. I've done similar with other nested objects but can't seem make it work with single table inheritance -- appointments table. For some reason inverse_of doesn't pass the id of the new referral to the appointment.

class Referral < ActiveRecord::Base

  has_many :appointments, class_name: 'Appointment::Base', inverse_of: :referral

  accepts_nested_attributes_for :appointments

end

class Appointment::Base < ActiveRecord::Base

  self.table_name = 'appointments'

  belongs_to :referral, inverse_of: :appointments

end

in the view

fields_for :appointments do |a|

Any help is appreciated.

Zach Colon
  • 177
  • 2
  • 11

1 Answers1

1

What about using the class_name for referral in the belongs_to clause? Like this:

class Appointment::Base < ActiveRecord::Base
  ...
  belongs_to :referral, class_name: 'Referral', inverse_of: :appointments
end

Rails may be looking in the same namespace as Base (Appointment) for Referral

guapolo
  • 2,443
  • 2
  • 20
  • 19