Why does the selected counter not work in yii?

can someone tell me why this does not work, what I mean is that select select does not work, not counting correctly;

$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 ), )); 
+4
source share
3 answers
 $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 ), )); 

The parameter name should also be :id_meeting

+3
source

Digging into Yii code, I realized that the only way to specify an arbitrary list of columns for count(distinct <columns>) is to provide a "select" for CDbCriteria as follows:

 $ar->count( 'select' => 'count(distinct <columns>)', 'condition' => ..., 'params' => ... ); 
+2
source

count api

public string count (mixed $ condition = '', array $ params = array ())

So, try passing params as an array to the second parameter of the count method.

ex.

 $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 ) ); 

Update: count , which are combined with ->with , do not work properly. Report an error.

Work around:

  BridgeMeeting::Model()->with('idUserRegistry')->count( array( 'condition' => 'id_meeting=' . $data->id_meeting, 'select' => 'id_user_registry', 'distinct' => true, ) ); 

And to debug this attempt to give a constant instead of $data->id_meeting

+1
source

Source: https://habr.com/ru/post/1469205/


All Articles