Customer::model()
->with('users', 'users.contributedExecutives')
->findAll('condition for selecting the one customer');
// or
Customer::model()
->with('users', 'users.contributedExecutives')
->together()
->findAll('...');
// or more recent style
//(with/together return type was changed from CActiveFinder to CActiveRecord)
Customer::model()->findAll($criteria_containing_with_together_condition);
Tommy – that will return a Customer model with users, right?
I have the customer model already. And I’ve shown code that demonstrates what I want to do – just get Executive models alone, and then manipulate them – display them as a list, sum up the total count, etc.
I’m not seeing how your code makes that happen any easier than what I illustrated above…?
Yeah I don’t see what that method is going to buy me over what I’ve already figured out…it’s even more verbose…
I am either going to go with the code that I figured out above or get the ‘through’ relation to work, but I’m thinking at this point that the relationship is doomed…
I did some testing with a through relationship similar to yours. Got some strange results (actually fewer elements than expected). So I think through is not an option (though I still don’t understand exactly how it’s intended to work).
This is what I would suggest instead (assuming your customer AR object in $model)
$users = User::model()
->with(contributedExecutives) // defined in User model
->findAll('t.fk_customer_id="'.$model->id.'"')
foreach ($users as $user)
foreach ($user->contributedExecutives as $executive)
echo 'Executive id: '.$executive->id.'<br/>';
or you have to define a BELONGS_TO relation (‘users’) in Executive and access like this
These last posts were as far as I got on the matter. Either my or Tommy’s solutions work… They really aren’t what I would expect from the framework but it appears Yii as of at least 1.1.8 does not support STAT relations that need a through clause. I’d love for one of the toolkit authors or maintainers to correct me. I should probably file a bug or request for enhancement.
Thanks for the reply, Preston, and for following through on this so diligently. Maybe it will be addressed in the future. I’m glad you found a workaround!