CDbCriteria + select

Предварительное обсуждение найденных ошибок перед отправкой их авторам фреймворка, а также внесение новых предложений.
Ответить
Аватара пользователя
yii
Сообщения: 122
Зарегистрирован: 2010.04.29, 10:40

CDbCriteria + select

Сообщение yii »

Может это и не баг, а так надо, тогда объясните пожалуйста. Делаю выборку:

Код: Выделить всё

$condition = array(
            'select' => 'sport.id AS sport_id, sport.title AS sport_title',
            'with' => array(
                'sport'
                ),
            'condition' => 'event_date > :event_date',
            'distinct' => true,
            'params' => array(
                ':event_date' => time(),
            )
        );
        $sports = UserBets::model()->findAll($condition); 
В результате формируется запрос:

Код: Выделить всё

SELECT DISTINCT sport.id AS sport_id, sport.title AS sport_title, `t`.`id` AS `t0_c0`, `sport`.`id` AS `t1_c0`, `sport`.`title` AS `t1_c1`, `sport`.`GameTimeShift` AS `t1_c2` FROM `user_bets` `t` LEFT OUTER JOIN `sports` `sport` ON (`t`.`sport_id`=`sport`.`id`) WHERE (event_date > :event_date) 
Откуда в запросе берутся

Код: Выделить всё

`t`.`id` AS `t0_c0`, `sport`.`id` AS `t1_c0`, `sport`.`title` AS `t1_c1`, `sport`.`GameTimeShift` AS `t1_c2` 
если было указано что выгребать только

Код: Выделить всё

'select' => 'sport.id AS sport_id, sport.title AS sport_title' 
Аватара пользователя
samdark
Администратор
Сообщения: 9489
Зарегистрирован: 2009.04.02, 13:46
Откуда: Воронеж
Контактная информация:

Re: CDbCriteria + select

Сообщение samdark »

Выборка начинается с UserBets, т.е. 'select' относится именно к нему. Надо так:

Код: Выделить всё

$condition = array(
            'with' => array(
                'sport' => array(
                   'select' => 'sport.id AS sport_id, sport.title AS sport_title',
                ),
            ),
            'condition' => 'event_date > :event_date',
            'distinct' => true,
            'params' => array(
                ':event_date' => time(),
            )
        );
        $sports = UserBets::model()->findAll($condition); 
 
Аватара пользователя
yii
Сообщения: 122
Зарегистрирован: 2010.04.29, 10:40

Re: CDbCriteria + select

Сообщение yii »

Так еще страшнее:

Код: Выделить всё

SELECT DISTINCT `t`.`id` AS `t0_c0`, `t`.`user_id` AS `t0_c1`, `t`.`bet_title` AS `t0_c2`, `t`.`interface` AS `t0_c3`, `t`.`sport_id` AS `t0_c4`, `t`.`level_id` AS `t0_c5`, `t`.`team_id` AS `t0_c6`, `t`.`player_id` AS `t0_c7`, `t`.`duration_type_id` AS `t0_c8`, `t`.`game_id` AS `t0_c9`, `t`.`month` AS `t0_c10`, `t`.`is_result` AS `t0_c11`, `t`.`is_statistic` AS `t0_c12`, `t`.`category_id` AS `t0_c13`, `t`.`category_stat_id` AS `t0_c14`, `t`.`user_bet` AS `t0_c15`, `t`.`condition_result_id` AS `t0_c16`, `t`.`condition_equal_id` AS `t0_c17`, `t`.`condition_time_id` AS `t0_c18`, `t`.`condition_period_id` AS `t0_c19`, `t`.`amount` AS `t0_c20`, `t`.`offer_odds` AS `t0_c21`, `t`.`offer_odds_value` AS `t0_c22`, `t`.`counterparties` AS `t0_c23`, `t`.`users_accepted` AS `t0_c24`, `t`.`pending` AS `t0_c25`, `t`.`tip` AS `t0_c26`, `t`.`event_date` AS `t0_c27`, `t`.`is_featured` AS `t0_c28`, `t`.`is_played` AS `t0_c29`, `t`.`is_win` AS `t0_c30`, `t`.`created_at` AS `t0_c31`, 
sport.id AS sport_id, sport.title AS sport_title, `sport`.`id` AS `t1_c0` 
FROM `user_bets` `t` 
LEFT OUTER JOIN `sports` `sport` ON (`t`.`sport_id`=`sport`.`id`) 
WHERE (event_date > :event_date) 
Ответить