So, I am trying to do this the right way using relations, rather than just crafting some SQL, but so far, all I am getting is a headache.

I have tables (and matching models) that are something like this:

fruit -< fruitMixMembers >- fruitMixes -< fruitBowls

the -< indicating a "has many" relationship, with a matching "belongs to" in each model.

so, fruit rows have an id,

fruitMixMembers has ids of multiple fruit and a id of a fruitMix

and fruitBowls has an id of a fruit mix and a pk identifying the bowl

so id like to find all the bowls that have a fruit of name "apple" in them.

in SQL I would do:

SELECT fruitBowls.* from fruitBowls B, fruitMixes M, fruitMixMembers X, fruit F WHERE‘Apple’ AND = X.fruitId AND AND

But my head scartching has so far failed to get me the correct sequence of calls in Yii

$bowls = FruitBowls::model()->with(‘fruitMixes’)

is about as far as I get before Things Go Wrong.

Someone point me inthe right direction?

This wiki uses both sql and relations. Should point you in the right direction.

Not really, that just performs a “many-many” relation across three tables … and unless I am mistaken, doesn’t do it via the “with” method call