findList() public method

When calling this finder, the fields passed are used to determine what should be used as the array key, value and optionally what to group the results by. By default the primary key for the model is used for the key, and the display field as value. The results of this finder will be in the following form: [ 1 => 'value for id 1', 2 => 'value for id 2', 4 => 'value for id 4' ] You can specify which property will be used as the key and which as value by using the $options array, when not specified, it will use the results of calling primaryKey and displayField respectively in this table: $table->find('list', [ 'keyField' => 'name', 'valueField' => 'age' ]); Results can be put together in bigger groups when they share a property, you can customize the property to use for grouping by setting groupField: $table->find('list', [ 'groupField' => 'category_id', ]); When using a groupField results will be returned in this format: [ 'group_1' => [ 1 => 'value for id 1', 2 => 'value for id 2', ] 'group_2' => [ 4 => 'value for id 4' ] ]
public findList ( Query $query, array $options ) : Query
$query Query The query to find with
$options array The options for the find
return Query The query builder
Example #1
0
 public function findList(Query $query, array $options)
 {
     if (!isset($options['keyField']) && !isset($options['valueField'])) {
         $select = $query->clause('select');
         if ($select && count($select) <= 2) {
             $keyField = array_shift($select);
             $valueField = array_shift($select) ?: $keyField;
             list($model, $keyField) = pluginSplit($keyField);
             if (!$model || $model === $this->alias()) {
                 $options['keyField'] = $keyField;
             }
             list($model, $valueField) = pluginSplit($valueField);
             if (!$model || $model === $this->alias()) {
                 $options['valueField'] = $valueField;
             }
         }
     }
     return parent::findList($query, $options);
 }