How do I make this relation?

41 views
Skip to first unread message

Luis

unread,
May 12, 2016, 2:28:12 PM5/12/16
to Ruby on Rails: Talk
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:


    
 

Colin Law

unread,
May 12, 2016, 3:28:49 PM5/12/16
to Ruby on Rails: Talk
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

Luis

unread,
May 12, 2016, 3:47:59 PM5/12/16
to Ruby on Rails: Talk
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

James Jelinek (shakycode)

unread,
May 12, 2016, 4:04:42 PM5/12/16
to rubyonra...@googlegroups.com
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




--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/931b38cb-15fe-40c5-b1a6-ce5dcf155c24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luis

unread,
May 12, 2016, 6:44:07 PM5/12/16
to Ruby on Rails: Talk
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. ;-) 

-Luis

Colin Law

unread,
May 13, 2016, 2:10:26 AM5/13/16
to Ruby on Rails: Talk


On 12 May 2016 11:44 p.m., "Luis" <luismc...@gmail.com> 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

> end 
>
> Same error
> BTW James I took that Benadryl. ;-) 
>
> -Luis
>
>
>
> On Thursday, May 12, 2016 at 2:28:12 PM UTC-4, Luis wrote:
>>
>> 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:
>>
>>
>>     
>>  
>

> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.

> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/30695cbf-a903-48f9-885c-0c08498e155a%40googlegroups.com.

Colin Law

unread,
May 13, 2016, 3:18:36 AM5/13/16
to Ruby on Rails: Talk
On 13 May 2016 at 07:10, Colin Law <cla...@gmail.com> wrote:
>
> On 12 May 2016 11:44 p.m., "Luis" <luismc...@gmail.com> 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.

Also the convention would be to call the key admiting_md_id

Colin

Luis

unread,
May 14, 2016, 7:27:38 PM5/14/16
to Ruby on Rails: Talk
Thanks Colin, that did it.
   
Reply all
Reply to author
Forward
0 new messages