Hi...... I would like to know what i ve done wrong in my association. I have 4 Models. user_info company_info department role Actually i want to get Particular user''s company,and which department he belongs and what role he has... These inforamtions i would like to get. So i made association. class CompanyInfo < ActiveRecord::Base #------------------------------------- has_one :user_info class UserInfo < ActiveRecord::Base belongs_to :company_info belongs_to :department belongs_to :role #------------------------------------- class Department < ActiveRecord::Base has_one :user_info #------------------------------------- class Role < ActiveRecord::Base has_one :user_info #------------------------------------- Now i can able to get department information for a paricular user and role inforamtion for a particular user. But i m unable to get Company information for a particular user. What would be the Problem in my case. Did i made anything wrong. Pls help me. -- 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 -~----------~----~----~----~------~----~------~--~---
The setup seems to be right, assuming there is a company_info_id in the user_info table. Are the records in the database ok and have the right id? What code do you use to get the CompanyInfo? Something like: @user_info = UserInfo(:first) That should allow to acces it like that: @user_info.company_info --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It seems all of your "has_one" should be has_many. A company, role and department should have many users. That might reduce problems with your associations. On Nov 13, 2:40 pm, Newb Newb <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi...... > I would like to know what i ve done wrong in my association. > I have 4 Models. > user_info > company_info > department > role > > Actually i want to get Particular user''s company,and which department he > belongs and what role he has... > These inforamtions i would like to get. > So i made association. > > class CompanyInfo < ActiveRecord::Base > #------------------------------------- > has_one :user_info > > class UserInfo < ActiveRecord::Base > > belongs_to :company_info > belongs_to :department > belongs_to :role > #------------------------------------- > class Department < ActiveRecord::Base > > has_one :user_info > #------------------------------------- > class Role < ActiveRecord::Base > > has_one :user_info > #------------------------------------- > Now i can able to get department information for a paricular user and > role inforamtion for a particular user. > But i m unable to get Company information for a particular user. > What would be the Problem in my case. > Did i made anything wrong. > Pls help me. > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---