Custom attributes in model
Posted 16 March 2017 - 01:47 PM
public function rules()
[['ID', 'PinNumber', 'TimeSpent'], 'integer'],
Now I want to add StartTime (computed, does not exist in the database) attribute that will be calculated based on LogTime and TimeSpent (StartTime = LogTime - TimeSpent).
What should I do to the model and search / filtering etc. in order to get this done properly?
Posted 17 March 2017 - 03:44 AM
"Then you need to compose a query, which calculates volume of the room and performs the sort."
Where and why? Didn't help that much.
I'd rather take my example and see what places are needed to be touched. Thanks.
Posted 19 March 2017 - 04:06 AM
Posted 20 March 2017 - 12:51 PM
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'StartTime' in 'order clause'
The SQL being executed was: SELECT * FROM `logs` ORDER BY `StartTime` LIMIT 20
Error Info: Array
 => 42S22
 => 1054
 => Unknown column 'StartTime' in 'order clause'
Posted 20 March 2017 - 03:03 PM
I've already defined the logic in the model how the StarTime is calculated. Do I really need to add that logic also to the query in order to get it working (that's how I understand the example, but is that correct)? Thx.
Posted 20 March 2017 - 03:58 PM
Yes, if you want to sort according to that attribute, you have to include it in the query as shown on that page. You don't have to calculate it elsewhere else, because the value will be returned by the query. If you don't need sorting, you can leave it out of the query.