Hi! I'm modeling my application and i have a question about relationships:
I have 3 classes (tables): User (users), Company (companies) and Rol (rols)
The relationship between the 3 classes is another table that has:
Joining table X
user_id
company_id
rol_id
Because a the same user can be in many companies. A company can have
many users. An a user have a single rol in a company but different
rols in another company.
So i can't name my table like users_companies because i have another
field, the rol_id so i should find another name, lets say X.
My model should be something like?:
class User < ActiveRecord::Base
has_many :X
has_many :companies, :through => X
end
class Company < ActiveRecord::Base
has_many :X
has_many :users, :through => X
end
class X < ActiveRecord::Base
belongs_to :company
belongs_to :users
has_one :rol
end
And rol isn't a class because just have the type of user ("Admin", "Regular").
Is this ok? Is my first time doing this kind of relationship