How do I make this relation?

I am trying to establish the following relation, but no joy!

Can someone please tell me how should I do this.

Thanks.
Luis

#Sched attributes:
#id
#…

pcp_id :integer

admitingMd_id :integer

class Sched < ActiveRecord::Base
belongs_to :admitingMd, :class_name => “Pcp”, :foreign_key => “:admitingMd_id”

#PCP attributes

#id
#…
class Pcp < ActiveRecord::Base
has_many :scheds
has_many :admitingMd, :primary_key => “admitingMd_id”, :foreing_key => “admitingMd_id”, :class_name => “Sched”

``

ArgumentError - Unknown key: :foreing_key. Valid keys are: :class_name, :anonymous_class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table, :foreign_type:

``

The clue is in the error message: Unknown key: :foreing_key
Which is how you have spelt it in the has_many line. It should be
foreign_key of course.

In addition I strongly suggest you stick to the rails conventions for
naming things. So you should not use a name like admitingMd. It
should be belongs_to :admiting_md and has_many admitting_mds (note the
plural for has-many). The key should be admiting_md_id. Are you sure
you don't mean admitting_md?

Colin

Hi Colin,

Yes you are correct I meant admitting_md.

My allergies are killing me but I need to finish this project soon. I posted like the 3rd version of the 5 tries

at this point I am making a lot of syntax due to how swollen my eyes are due to the pollen allergy. My apologies in advance!

I’ll give it another try

Thanks

-Luis

Benadryl will help with the allergies, Colin’s suggestions on following Rails conventions and naming your associations and classes will help with the code part.

Good luck!

Cheers,

James

Subscribe to my Youtube Channel: https://www.youtube.com/shakycode

Ok there is something that I am not getting in here I think this should work. What am I missing ?

class Sched < ActiveRecord::Base

belongs_to :admiting_md, :foreign_key => :admiting_md ,:class_name => “Pcp”

end

class Pcp < ActiveRecord::Base

has_many :admiting_mds, :foreing_key => :admiting_md, :class_name => “Sched”

end

Same error

BTW James I took that Benadryl. :wink:

-Luis

Ok there is something that I am not getting in here I think this should work. What am I missing ?

class Sched < ActiveRecord::Base
belongs_to :admiting_md, :foreign_key => :admiting_md ,:class_name => “Pcp”
end

class Pcp < ActiveRecord::Base
has_many :admiting_mds, :foreing_key => :admiting_md, :class_name => “Sched”

You have still misspelt foreign.

Colin

Also the convention would be to call the key admiting_md_id

Colin

Thanks Colin, that did it.