Hi, Here''s the thing : I have a table with languages (name, label, id). languages id name label I''d like another table people with primary_language and secondary_langage that should refer to a language_id. people id firstname familyname primary_language -> language_id secondary_language -> language_id Because I got 2 references, I don''t know how I can do. I think I have to explicitly say in the Person and Language model that primary_language and secondary_language is a language_id. How can I do ? Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Here''s how the table would look: people id firstname familyname primary_language -> primary_language_id secondary_language -> secondary_language_id And the class: class Person belongs_to :primary_language, :class_name => ''Language'' belongs_to :secondary_language, :class_name => ''Language'' end - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) João Pessoa, PB, +55 83 8867-7208 On Thu, Oct 30, 2008 at 10:12 AM, David Nguyen <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > > Here''s the thing : > I have a table with languages (name, label, id). > > languages > id > name > label > > I''d like another table people with primary_language and > secondary_langage > that should refer to a language_id. > > people > id > firstname > familyname > primary_language -> language_id > secondary_language -> language_id > > > Because I got 2 references, I don''t know how I can do. I think I have to > explicitly say in the Person and Language model that primary_language > and secondary_language is a language_id. How can I do ? > > Thanks > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
For assigning the language id you need to assign the language_id before saving the record. this should be record.primary_language_id = language.id record.secondary_language_id = language.id record.save! In your person model you can say, belongs_to :primary_language, :class_name => "Language", :foreign_key => "primary_language_id" for the relation ship. So in this case People.primary_language will be the language record. As for the Rails coding use the column name as "primary_language_id" instead of "primary_language".> > people > id > firstname > familyname > primary_language -> language_id > secondary_language -> language_id > > > Because I got 2 references, I don''t know how I can do. I think I have to > explicitly say in the Person and Language model that primary_language > and secondary_language is a language_id. How can I do ? > > Thanks-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---