CakePHP 3.x
I have records which have a sq. mileage field. I want to sum these fields by date, so regardless of display page, order, etc. the value by entity will be the same. e.g.:
|id| date |sqmiles|total| |--|----------|-------|-----| |1 |2010-10-10| 2 | 2 | |2 |2011-11-11| 3 | 5 | |3 |2012-12-12| 1 | 6 |
|id| date |sqmiles|total| |--|----------|-------|-----| |3 |2012-12-12| 1 | 6 | |1 |2010-10-10| 2 | 2 | |2 |2011-11-11| 3 | 5 |
My starting thoughts were a virtual field where it requests the following SQL: SELECT SUM(sq_miles) FROM table WHERE date <= ($this->_properties['date']);
but with CakePHP3’s new ORM I don’t know how to put that into code in the entity.