I am trying to add an isOnline field for users which does not exists in the database. Is there a way In can return isOnline as a virtual field? I have tried adding this to the User entity:
protected function _getIsOnline() {
return true;
}
But when I do a $user->find('all', [])
the field is not included. Any ideas on how to accomplish this?
You cannot use use virtual fields within the query object. Any filtering would have to take place after retrieving the data from the query. Virtual fields are lazy loaded, so they do not exist until required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With