I’m new to the Yii, so I can’t write the solution in AR Relations, but there is guide for it.
In SQL it looks like so:
SELECT industries.* FROM town2industry JOIN industries ON (town2industry.industry_id = industries.id) WHERE town2industry.town_id=1
I think in AR Relations it would be something like getting items from junction table, joining industries. So in your loop you will do someting like this:
foreach($town->town2industry as $t2i) {
$t2i->industry; // here is the industry
}
In the end I just decided to define 2 relations. One to access the "middle" table, and one to access the "relation" table through the "middle" table and I used the 2 relations under different circumstances.