I have the following relations
company (id, ...) region (id, company_id, ...) division (id, region_id, ...) user (id, division_id, ...)
A company has many regions, a region has many divisions and a division has many users.
Given a user, I want to find the company the user belongs to, so a simple sql query to find this would be
select company.* from company, region, division, user where company.id = region.company_id AND region.id = division.region_id AND division.id = user.division_id AND user.id = ?????;
HOWEVER what I need to know is:
Is it possible to define a relation in the User model to retrieve the related company.
Thus I can simply perform a query such as
If its not possible to define this with a relation could it be done with a model method?
Any help would be appreciated.