I have a some warnings about the referencing of foreign key, i did try several way to solve this problem but i am still stuck with foreign key. is the syntax of setting foreign key is wrong? can anyone help to fix the problem ~user table id name address guest ~ prescription table id person (integer) picture date_written ~user model has_many :prescriptions ~ prescription model belongs_to :person, :foreign_key => "person" ,:class_name => ''User'' ~userTest context "belong to and have many association " do should have_many :prescriptions end ~prescriptionTest context "belongs to relationship" do should belong_to :person end 1) Failure: test: belong to and have many association should have many prescriptions. (UserTest) [/usr/local/lib/ruby/gems/1.9.1/gems/ shoulda-2.11.3/lib/shoulda/context.rb:324]: Expected User to have a has_many association called prescriptions (Prescription does not have a user_id foreign key.). Expected block to return true value. thanks -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 12 July 2011 19:22, Yennie <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a some warnings about the referencing of foreign key, > i did try several way to solve this problem but i am still stuck with > foreign key. > is the syntax of setting foreign key is wrong? > > can anyone help to fix the problem > > > ~user table > id > name > address > guest > > > ~ prescription table > id > person (integer) > picture > date_written > > ~user model > has_many :prescriptionsAs in the other thread I think you need to specify the foreign key here also. As a matter of interest why are you specifying all these non-standard foreign keys rather than the default> > ~ prescription model > belongs_to :person, :foreign_key => "person" ,:class_name => ''User''Again as I suggested much earlier I think you will run into problems with the name of the foreign key the same as the model. If you say @prescription.person how will rails know whether you mean the foreign key field (which is an integer) or the associated user? person_id would be more conventional and safer I think. Colin> > > ~userTest > context "belong to and have many association " do > should have_many :prescriptions > end > > ~prescriptionTest > context "belongs to relationship" do > should belong_to :person > end > > > 1) Failure: > test: belong to and have many association should have many > prescriptions. (UserTest) [/usr/local/lib/ruby/gems/1.9.1/gems/ > shoulda-2.11.3/lib/shoulda/context.rb:324]: > Expected User to have a has_many association called prescriptions > (Prescription does not have a user_id foreign key.). > Expected block to return true value. > > > thanks > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 12, 4:04 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 12 July 2011 19:22, Yennie <joanne0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > I have a some warnings about the referencing offoreignkey, > > i did try several way to solve this problem but i am still stuck with > >foreignkey. > > is the syntax of settingforeignkeyis wrong? > > > can anyone help to fix the problem > > > ~user table > > id > > name > > address > > guest > > > ~ prescription table > > id > > person (integer)person_id => This is a foreign key of user I change like that. but it''s still giving me warning... please help...> > picture > > date_written > > > ~user model > > has_many :prescriptions > > As in the other thread I think you need to specify theforeignkeyhere also. > As a matter of interest why are you specifying all these non-standardforeignkeys rather than the default > > > > > ~ prescription model > > belongs_to :person, :foreign_key => "person" ,:class_name => ''User''belongs_to :user, :foreign_key => "person_id" ,:class_name => ''User''> > Again as I suggested much earlier I think you will run into problems > with the name of theforeignkeythe same as the model. If you say > @prescription.person how willrailsknow whether you mean theforeignkeyfield (which is an integer) or the associated user? person_id > would be more conventional and safer I think. > > Colin > > > > > > > > > > > ~userTest > > context "belong to and have many association " do > > should have_many :prescriptions > > end > > > ~prescriptionTest > > context "belongs to relationship" do > > should belong_to :personshould belong_to :user> > end > > > 1) Failure: > > test: belong to and have many association should have many > > prescriptions. (UserTest) [/usr/local/lib/ruby/gems/1.9.1/gems/ > > shoulda-2.11.3/lib/shoulda/context.rb:324]: > > Expected User to have a has_many association called prescriptions > > (Prescription does not have a user_idforeignkey.). > > Expected block to return true value. > > > thanks > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby onRails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 13 July 2011 01:54, Yennie <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> [big snip]So is it all working now? If not then show us the current code and error if you want more help. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.