Alexander Kutuev
Alexander Kutuev

Reputation: 1

yii2 active record query

I need to make query (in search model) where:

  1. Get current row index (not id)
  2. Do a manipulation with that count (multiply this on constant number) and add if condition (if 'row index' > 10)
  3. See this count in the model

Some steps I resolve:

  1. I know how to create 'new column' and see it in the gridview:

    $query->select([
        '{{tour}}.*',
        '(1000 / 'need to add row index' ) as points' //$points
    ]);
    
  2. I know how to get a current index, but with active record:

MyModel::find()->andFilterWhere(['>=', 'cumulative_points', $playerPoints])->count();

But I need to combine this query. Anybody can help me? Thanks.

Upvotes: 0

Views: 414

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133370

When you need you can express the content of SQL part like literal and then assign the select content you prefer (not using array / hash assignment) this way

 $query->select(' tour.*, 1000 / id ) as points' ) 

Sostantially you can assign to activeQuery select() method exactly the select part of you query ..

http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html

Upvotes: 0

Related Questions