I am getting an error invalid argument supplied for foreach
I am trying to Outer Join two tables
Player and Player Season
I want all Players Historically but if they are set up for the current season I want to show the current season settings. I have an Inner Join on Player Season where Season_id is this season then outer join with Player. I did the inner join because I couldn’t think of how to do the select without it. In MySql workbench the query works. I am looking for suggestions on how to see the sql I’m sending or suggestions on what may be the invalid argument. The error line is C:\xampp\yii\framework\db\ar\CActiveFinder.php(838)
SQL that works is:
select p.id,p.last_name,p.first_name,p.address,p.phone_1,p.phone_2,p.email,ps.* from tbl_player_season ps INNER JOIN (SELECT t.player_id FROM tbl_player_season t WHERE t.season_id = 2)
as slt ON slt.player_id = ps.player_id RIGHT JOIN tbl_player p ON ps.player_id = p.id;
In my model:
public function searchPlayerJoin()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->join='INNER JOIN (SELECT * FROM tbl_player_season ps WHERE ps.season_id = '.SeasonLeague::model()->getCurrentSeasonID().')
as slt ON slt.player_id = t.player_id
RIGHT JOIN tbl_player p ON t.player_id = p.id';
$criteria->compare('player_id',$this->player_id);
$criteria->compare('season_id',$this->season_id);
$criteria->compare('comment',$this->comment,true);
$criteria->compare('date_of_application',$this->date_of_application,true);
$criteria->compare('current_league_id',$this->current_league_id);
$criteria->compare('number_of_seasons',$this->number_of_seasons);
$criteria->compare('pitcher_catcher',$this->pitcher_catcher,true);
$criteria->compare('jersey_size',$this->jersey_size,true);
$criteria->compare('pant_size',$this->pant_size,true);
$criteria->compare('short_size',$this->short_size,true);
$criteria->compare('tshirt_size',$this->tshirt_size,true);
$criteria->compare('league.league_name',$this->league_name,true);
$criteria->compare('player.first_name',$this->first_name,true);
$criteria->compare('player.last_name',$this->last_name,true);
$criteria->with=array('currentLeague');
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
In my view:
$playerSeasonInstance = new PlayerSeason();
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$playerSeasonInstance->searchPlayerJoin(),
'id'=>'currentplayers-grid',
'filter'=>$playerSeasonInstance,
'columns'=>array(
'last_name',
'first_name',
/*'league_name',
'date_of_application',
'comment',*/
)));