Forum: Ruby on Rails association

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
3083ca8f0496edaac2fa10c20630d0bc?d=identicon&s=25 Newb Newb (newb)
on 2008-11-13 07:40
I would like to know what i ve done wrong in my association.
I have 4 Models.

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.
2d8132658d56e51f19ace1c68e48b6aa?d=identicon&s=25 Thorsten Mueller (thorsten)
on 2008-11-13 11:35
(Received via mailing list)
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:
Dd85c761c8d8adab6d2608ede23be346?d=identicon&s=25 yachtman (Guest)
on 2008-11-13 16:20
(Received via mailing list)
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 <>
This topic is locked and can not be replied to.