Hey,
I’ve got 3 tables - Team, Player, and Goal. A Team has many players, and a player can have many goals. I would like to query all the goals scored on a team for a specific date range.
I currently have a relation on Team CActiveRecord like the following:
class Team extends CActiveRecord
{
...
public function relations()
{
return array(
'players' => array(self::HAS_MANY, 'Player', 'teamID'),
'goals'=>array(
self::HAS_MANY,'Goal',array('playerID'=>'playerID'),'through'=>'players'
),
);
}
}
This works great for retrieving all the Goals for a specific team, but I’m not sure how I would query all the Goals on a Team for the past week.
FYI: Goal has a DATETIME column ‘time’ in which is set on the time the Goal occurred.
I’m assuming this is not possible using a Relation, but rather I’d have to use Team::model->findAll(…Condition…); But I don’t know how I’d properly join to the Goal table (like the ‘through’ command in the relation).
Of course I could do this all with Raw SQL, but I want to know the best ‘Yii’ way.
Thanks in advance!