Using multiple valueFields in find('list')

后端 未结 3 545
无人共我
无人共我 2021-01-29 01:24

Trying to use multiple fields in my find method -

$users = $this->AdressesUsers->users->find(\'list\', [
            \'keyField\' => \'id\',
                 


        
3条回答
  •  闹比i
    闹比i (楼主)
    2021-01-29 02:21

    I'd suggest you to use Queries As Collection Objects here. Try this:

    $users = $this->AdressesUsers->Users->find()
                  ->map(function ($row) { // map() is a collection method, it executes the query
                      $row->fullName = $row->firstname . ' ' . $row->lastname;
                      return $row;
                   })
                   ->combine('id', 'fullName') // combine() is another collection method
                   ->toArray(); // Also a collections library method
    
    pr($users);  // Check your result
    

提交回复
热议问题