I have a relationship like this:
class Workout extends CActiveRecord {
public function relations()
{
return array(
'userWorkouts' => array(self::HAS_MANY, 'UserWorkout', 'workout_id'),
'users' => array(self::HAS_MANY, 'User', 'user_id', 'through' => 'userWorkouts'),
);
}
}
class User extends CActiveRecord {
public function relations()
{
return array(
'userWorkouts' => array(self::HAS_MANY, 'UserWorkout', 'user_id'),
'workouts' => array(self::HAS_MANY, 'Workout', 'workout_id', 'through' => 'userWorkouts'),
);
}
}
So a $user has multiple $workouts through the join table $userWorkout. I need to be able to get a users workouts filtered by a condition using a property of workout. So something like this:
$user->workouts->where(‘workout.end_date’ = 0);
Any advice?