Is there a way to dynamically modify the criteria given in Yii’s relations model?
For example, I have this relationship in a Game model that will give me all of the points earned for it
'total_points' => [self::STAT, 'Point', 'game_id', 'select' => 'SUM(earned)']
This works just fine. However, I want to be able to pare this down based on a specific user ID chosen dynamically.
How would I create a method like the following that would return total_points earned in this game for a specific, changing user, where user_id is an attribute of the Point model?
function getUserPoints($user_id) {
return $this->someCriteriaChangingMethod('user_id = $user_id')->total_points;
}
By yii guide this should work:
Is this what you want?