Ouzo\Db\RelationFetcher::transform PHP Метод

transform() публичный Метод

public transform ( &$results )
    public function transform(&$results)
    {
        $localKeyName = $this->_relation->getLocalKey();
        $localKeys = FluentArray::from($results)->map(Functions::extractField($localKeyName))->filterNotBlank()->unique()->toArray();
        $relationObjectsById = $localKeys ? $this->_loadRelationObjectsIndexedById($localKeys) : array();
        foreach ($results as $result) {
            $values = $this->_findRelationObject($relationObjectsById, $result->{$localKeyName});
            $destinationField = $this->_relation->getName();
            $result->{$destinationField} = $this->_relation->extractValue($values);
        }
    }

Usage Example

Пример #1
0
 public function transform(&$results)
 {
     if ($this->field) {
         $fields = FluentArray::from($results)->map(Functions::extractExpression($this->field))->flatten()->filterNotBlank()->toArray();
         $this->transformer->transform($fields);
     } else {
         $this->transformer->transform($results);
     }
 }
All Usage Examples Of Ouzo\Db\RelationFetcher::transform