Ruby on rails rails联合使用Unizillaize常量
我想找出外科医生和预约之间的关系Ruby on rails rails联合使用Unizillaize常量,ruby-on-rails,ruby-on-rails-4,model-associations,Ruby On Rails,Ruby On Rails 4,Model Associations,我想找出外科医生和预约之间的关系 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", up
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
但这是有效的
2.0.0-p195:007>外科医生协会:预约
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
这是我的模型
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
模型必须以单数命名,而不是复数
class Appointment < ActiveRecord::Base
谢谢我已经改正了。然后我重新装弹!我的控制台。但是我仍然有名称错误:未初始化的常量外科医生::任命2.0.0-p195:006>survior.methods.grep/appoint/=>[:自动保存约会的相关记录,:验证约会的相关记录,:在添加约会之前,:在添加约会之前,:在添加约会之前,:在添加约会之前,:在添加约会之前,:在添加约会之后,:在添加约会之后,:在添加约会之后,:在添加约会之后,:在添加约会之前,:在删除约会之前,:在删除约会之前,:在删除约会之前,:在e_remove_for_约会=,:after_remove_for_约会?,:after_remove_for_约会=,:约会,:约会ID,:约会=,:约会ID=]2.0.0-p195:007>外科医生.appointment\u id name错误:未初始化的常量外科医生::appointment尝试终止控制台并重复这些步骤。首先,我不知道控制台是否在重新加载后在新类上启动!其次,我确实知道,在从数据库重新加载之前,它实际上不会重新调整对象的斜体,请参阅