-1

I'm trying to find the relations between Surgeon and Appointments.

2.0.0-p195 :001 > surgeon = Surgeon.first
  Surgeon Load (0.1ms)  SELECT "surgeons".* FROM "surgeons" ORDER BY "surgeons"."id" ASC LIMIT 1
 => #<Surgeon id: 5, name: "Micheal Gorbachev", created_at: "2014-04-13 07:15:42", updated_at: "2014-04-13 07:15:42"> 

2.0.0-p195 :008 > surgeon.appointments
NameError: uninitialized constant Surgeon::Appointment

but this works

2.0.0-p195 :007 > surgeon.association :appointments

  2.0.0-p195 :007 > surgeon.association :appointments
   => #<ActiveRecord::Associations::HasManyAssociation:0x00000002a46850 
   @reflection=#<ActiveRecord::Reflection::AssociationReflection:0x000000030dc4d0 
   @macro=:has_many, @name=:appointments, @scope=nil, @options={}, 
   @active_record=Surgeon(id: integer, name: string, created_at: datetime, 
   updated_at: datetime), @plural_name="appointments", @collection=true>, 
   @owner=#<Surgeon id: 5, name: "Micheal Gorbachev", created_at: "2014-0

enter image description here

this is my Model

class Surgeon < ActiveRecord::Base
       has_and_belongs_to_many :instruments

       #section 2
       has_many :appointments
       has_many :interventions, :through => :appointments
    end
    class Intervention < ActiveRecord::Base
      has_and_belongs_to_many :instruments

      #section 2
      has_many :appointments
      has_many :surgeons, :through => :appointments
    end
    class Instrument < ActiveRecord::Base
       has_and_belongs_to_many :surgeons
       has_and_belongs_to_many :interventions
    end
    class Appointments < ActiveRecord::Base

      #section 2
      belongs_to :surgeon
      belongs_to :intervention
    end
Papouche Guinslyzinho
  • 5,277
  • 14
  • 58
  • 101

1 Answers1

0

Models must be named in singular, not plural.

class Appointment < ActiveRecord::Base
Jakub K
  • 1,713
  • 1
  • 13
  • 21
  • thanks! I have made the correction. than I reload! my console. But I still have the `NameError: uninitialized constant Surgeon::Appointment` – Papouche Guinslyzinho Apr 13 '14 at 20:40
  • `2.0.0-p195 :006 > surgeon.methods.grep /appoint/ => [:autosave_associated_records_for_appointments, :validate_associated_records_for_appointments, :before_add_for_appointments, :before_add_for_appointments?, :before_add_for_appointments=, :after_add_for_appointments, :after_add_for_appointments?, :after_add_for_appointments=, :before_remove_for_appointments, :before_remove_for_appointments?, :before_remove_for_appointments=, :after_remove_for_appointments, :after_remove_for_appointments?, :after_remove_for_appointments=, :appointments, :appointment_ids, :appointments=, :appointment_ids=] ` – Papouche Guinslyzinho Apr 13 '14 at 20:41
  • `2.0.0-p195 :007 > surgeon.appointment_ids NameError: uninitialized constant Surgeon::Appointment` – Papouche Guinslyzinho Apr 13 '14 at 20:42
  • Try killing the console and repeating the steps. For one I don't know if the console picks up on your new class after just `reload!`, second I do know that it doesn't actually reinitalize the objects until you reload from the database, see http://stackoverflow.com/questions/5427596/rails-console-reload-not-reflecting-changes-in-model-files-what-could-be-poss – Jakub K Apr 13 '14 at 21:05