Best way to query a join

I’m struggling to work out what the best way is of doing a query.

I have four tables, the first, data_category defines categories for the different types of data.

The second, data_type, defines the different types of data. Each data_type belongs to a data_category. Each data_category has one or more data_types.

The third, data_set, defines each of the actual data sets. Each data_set belongs to a data_type and each data_type has one or more data_sets.

So, a fairly straightforward hierachy and I’ve set-up the required relationships in the corresponding models.

I also have a company table, which defines all the companies using the sites. Each data_set belongs to a company and each company has one or more data_sets.

I want to do a fairly simple query which is ‘find me all the data_sets in category A that belong to company Z’. (In fact, it’s probably slightly simpler because really all I want is to know if there are any data_sets in category A that belong to company Z.)

I could fairly easily put the SQL together for this and use findAllBySql (or countBySQL) but I’m wondering if there is a more elegant ‘yii’ way of putting a query like this together?