CackePHP 3 formatResults() ORDER by field created dynamically
I wish to sort on a field that I dynamically creates in formatResults() $users = $this->Users ->find('all') ->formatResults(function ($users) use ($lat, $lng) { return $users->map(function ($user) use ($lat, $lng) { $user->distance = getDist($lat, $lng); return $user; }); }) ->order([ 'distance' => 'ASC' ]); [...] $this->set('users', $this->paginate($users)); The field $user->distance is not in the database. $user->distance contains a float ( getDist($lat, $lng); ) that is variable depending on the position of the user at the time of his request. ->order([ 'distance' => 'ASC' ]); return an