ruby - Report/Reports on model in rails -
hi create model relations other once i'm surprised pluralize option of rails. mean.
i create model this:
rails g model report name:string....   like did with:
rails g model patient name:string... rails g model doctor name:string....   doctor has many patients can go console , type:
patient.doctor => gives me doctor patient doctor.patients => gives me patients doctor (note patients in plural)   and here strange thing, did same report , expect have command:
patient.reports (note plural)   but instead of if want retrieve patient reports have do:
patient.report (note singular)... , works!   does can illuminate blindness?
the methods retrieve related object(s) depends on how you've declared in model.
some examples:
class patient < activerecord::base   belongs_to :doctor # singular end  class doctor < activerecord::base   has_many :patients # plural end   then can do:
patient.doctor # => return associated doctor if exists doctor.patients # => return patients of doctor if exist   i think you've declared relation in singular:
# think have class patient < activerecord::base   has_many :report end   but should use plural here:
# think should use class patient < activerecord::base   has_many :reports                   ^                   # make plural end      
Comments
Post a Comment