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:

On 12 May 2016 at 19:28, Luis [email protected] wrote:

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
https://www.youtube.com/c/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

On 13 May 2016 at 07:10, Colin L. [email protected] wrote:

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

You have still misspelt foreign.

Also the convention would be to call the key admiting_md_id

Colin

Thanks Colin, that did it.

On 12 May 2016 11:44 p.m., “Luis” [email protected] wrote:

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

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:


You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected]
To post to this group, send email to [email protected]
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/30695cbf-a903-48f9-885c-0c08498e155a%40googlegroups.com
.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs