original_string: public function findVersions(Query $query, array $options)
      {
          $association = $this->versionAssociation();
          $name = $association->getName();
  
          return $query
              ->contain([$name => function (Query $q) use ($name, $options, $query) {
                  if (!empty($options['primaryKey'])) {
                      $foreignKey = (array)$this->_config['foreignKey'];
                      $aliasedFK = [];
                      foreach ($foreignKey as $field) {
                          $aliasedFK[] = "$name.$field";
                      }
                      $conditions = array_combine($aliasedFK, (array)$options['primaryKey']);
                      $q->where($conditions);
                  }
                  if (!empty($options['versionId'])) {
                      $q->where(["$name.version_id IN" => $options['versionId']]);
                  }
                  $q->where(["$name.field IN" => $this->_fields()]);
  
                  return $q;
              }])
              ->formatResults([$this, 'groupVersions'], $query::PREPEND);
      }
code: public function findVersions(Query $query, array $options)
      {
          $association = $this->versionAssociation();
          $name = $association->getName();
  
          return $query
              ->contain([$name => function (Query $q) use ($name, $options, $query) {
                  if (!empty($options['primaryKey'])) {
                      $foreignKey = (array)$this->_config['foreignKey'];
                      $aliasedFK = [];
                      foreach ($foreignKey as $field) {
                          $aliasedFK[] = "$name.$field";
                      }
                      $conditions = array_combine($aliasedFK, (array)$options['primaryKey']);
                      $q->where($conditions);
                  }
                  if (!empty($options['versionId'])) {
                      $q->where(["$name.version_id IN" => $options['versionId']]);
                  }
                  $q->where(["$name.field IN" => $this->_fields()]);
  
                  return $q;
              }])
              ->formatResults([$this, 'groupVersions'], $query::PREPEND);
      }
code_tokens: public function findVersions ( Query $ query , array $ options ) { $ association = $ this -> versionAssociation ( ) ; $ name = $ association -> getName ( ) ; return $ query -> contain ( [ $ name => function ( Query $ q ) use ( $ name , $ options , $ query ) { if ( ! empty ( $ options [ 'primaryKey' ] ) ) { $ foreignKey = ( array ) $ this -> _config [ 'foreignKey' ] ; $ aliasedFK = [ ] ; foreach ( $ foreignKey as $ field ) { $ aliasedFK [ ] = "$name.$field" ; } $ conditions = array_combine ( $ aliasedFK , ( array ) $ options [ 'primaryKey' ] ) ; $ q -> where ( $ conditions ) ; } if ( ! empty ( $ options [ 'versionId' ] ) ) { $ q -> where ( [ "$name.version_id IN" => $ options [ 'versionId' ] ] ) ; } $ q -> where ( [ "$name.field IN" => $ this -> _fields ( ) ] ) ; return $ q ; } ] ) -> formatResults ( [ $ this , 'groupVersions' ] , $ query :: PREPEND ) ; }
docstring: Custom finder method used to retrieve all versions for the found records.
  
  Versioned values will be found for each entity under the property `_versions`.
  
  ### Example:
  
  {{{
  $article = $articles->find('versions')->first();
  $firstVersion = $article->get('_versions')[1];
  }}}
  
  @param \Cake\ORM\Query $query The original query to modify
  @param array $options Options
  @return \Cake\ORM\Query
docstring_tokens: Custom finder method used to retrieve all versions for the found records .