有人可以告诉我为什么这不起作用,我的意思是选择distinct不能正常工作;
$count_participants = BridgeMeeting::Model()->with('idUserRegistry')->count(array(
'condition' => 'id_meeting=:id_meeting',
'select' => 'id_user_registry',
'distinct' => true,
'params' => array(
"id_meeting" => $data->id_meeting
),
));
答案 0 :(得分:3)
$count_participants = BridgeMeeting::Model()->with('idUserRegistry')->count(array(
'condition' => 'id_meeting=:id_meeting',
'select' => 'id_user_registry',
'distinct' => true,
'params' => array(
":id_meeting" => $data->id_meeting
),
));
参数名称也应为:id_meeting
答案 1 :(得分:2)
深入研究Yii的代码我发现,为count(distinct <columns>)
指定任意列列表的唯一方法是为CDbCriteria提供'select',如下所示:
$ar->count(
'select' => 'count(distinct <columns>)',
'condition' => ...,
'params' => ...
);
答案 2 :(得分:1)
count
api
公共字符串计数(混合$ condition =&#39;&#39;,array $ params = array())
因此,尝试将 params
作为数组传递给第二个计数方法的参数。
离。
$count_participants = BridgeMeeting::Model()->with('idUserRegistry')->count(
array(
'condition' => 'id_meeting=:id_meeting',
'select' => 'id_user_registry',
'distinct' => true,
),
array(
"id_meeting" => $data->id_meeting
)
);
count
合并的 更新 ->with
无效。必须报告错误。
解决方法是:
BridgeMeeting::Model()->with('idUserRegistry')->count(
array(
'condition' => 'id_meeting=' . $data->id_meeting,
'select' => 'id_user_registry',
'distinct' => true,
)
);
要调试此尝试给出常量而不是$data->id_meeting