How is it possible to define just simple custom attribute? I’ve got the following information:
public function rules()
{
return [
[['ID', 'PinNumber', 'TimeSpent'], 'integer'],
[['LogTime'], 'safe'],
];
}
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?
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.
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.