A
A
Alexander Fedorov2015-10-15 13:48:18
Yii
Alexander Fedorov, 2015-10-15 13:48:18

How to get the sum of a table with a condition in Yii2 using AR?

I'm trying to get the sum of records from a table with a date condition.
The code is the following:
$reportDate = '2015-10-01';

$saldo = Transaction::find()
                ->sum('')
                ->andWhere('<', '', $reportDate)
                ;

column type transaction_date = date.
Yii gives an error on this: Call to a member function andWhere() on string
If you remove the andWhere condition , then the request is processed normally.
I'm doing something wrong... :) But reading the sections of the documentation Active Record and sum() did not answer the question.
Tell me, please, how is it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fedornabilkin, 2018-07-24
@fedornabilkin

The ->andWhere method is used when the ->where method has already been used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question