public function reduce(Operation $operation, $inBetween)
    {
        if ($operation instanceof DeleteModel &&
            $this->name === $operation->name && !$this->getMeta()->proxy) {
            return [];
        }

        if ($operation instanceof FieldOperation &&
            strtolower($operation->modelName) === strtolower($this->name)) {
            if ($operation instanceof AddField) {
                // check if there is an operation in between that references
                // the same model if so, don't merge
                if ($operation->field->relation) {
                    foreach ($inBetween as $between) {
                        $modelName = $operation->field->relation
                            ->toModel->getMeta()->getNSModelName();
                        if ($between->referencesModel($modelName)) {
                            return false;
                        }

                        if ($operation->field->relation
                                ->hasProperty('through') &&
                            $operation->field->relation->through
                        ) {
                            $modelName = $operation->field->relation
                                ->through->getMeta()->getNSModelName();
                            if ($between->referencesModel($modelName)) {
                                return false;
                            }
                        }
                    }
                }

                $fields = $this->fields;
                $fields[$operation->field->getName()] = $operation->field;

                $op = static::createObject(
                    [
                        'name' => $this->name,
                        'fields' => $fields,
                        'meta' => $this->getMeta(),
                        'extends' => $this->extends,
                    ]
                );
                $op->setAppLabel($this->getAppLabel());

                return [
                    $op,
                ];
            }
        }

        return parent::reduce($operation, $inBetween);
    }
public function reduce(Operation $operation, $inBetween)
    {
        if ($operation instanceof DeleteModel &&
            $this->name === $operation->name && !$this->getMeta()->proxy) {
            return [];
        }

        if ($operation instanceof FieldOperation &&
            strtolower($operation->modelName) === strtolower($this->name)) {
            if ($operation instanceof AddField) {
                // check if there is an operation in between that references
                // the same model if so, don't merge
                if ($operation->field->relation) {
                    foreach ($inBetween as $between) {
                        $modelName = $operation->field->relation
                            ->toModel->getMeta()->getNSModelName();
                        if ($between->referencesModel($modelName)) {
                            return false;
                        }

                        if ($operation->field->relation
                                ->hasProperty('through') &&
                            $operation->field->relation->through
                        ) {
                            $modelName = $operation->field->relation
                                ->through->getMeta()->getNSModelName();
                            if ($between->referencesModel($modelName)) {
                                return false;
                            }
                        }
                    }
                }

                $fields = $this->fields;
                $fields[$operation->field->getName()] = $operation->field;

                $op = static::createObject(
                    [
                        'name' => $this->name,
                        'fields' => $fields,
                        'meta' => $this->getMeta(),
                        'extends' => $this->extends,
                    ]
                );
                $op->setAppLabel($this->getAppLabel());

                return [
                    $op,
                ];
            }
        }

        return parent::reduce($operation, $inBetween);
    }
public function reduce ( Operation $ operation , $ inBetween ) { if ( $ operation instanceof DeleteModel && $ this -> name === $ operation -> name && ! $ this -> getMeta ( ) -> proxy ) { return [ ] ; } if ( $ operation instanceof FieldOperation && strtolower ( $ operation -> modelName ) === strtolower ( $ this -> name ) ) { if ( $ operation instanceof AddField ) { // check if there is an operation in between that references // the same model if so, don't merge if ( $ operation -> field -> relation ) { foreach ( $ inBetween as $ between ) { $ modelName = $ operation -> field -> relation -> toModel -> getMeta ( ) -> getNSModelName ( ) ; if ( $ between -> referencesModel ( $ modelName ) ) { return false ; } if ( $ operation -> field -> relation -> hasProperty ( 'through' ) && $ operation -> field -> relation -> through ) { $ modelName = $ operation -> field -> relation -> through -> getMeta ( ) -> getNSModelName ( ) ; if ( $ between -> referencesModel ( $ modelName ) ) { return false ; } } } } $ fields = $ this -> fields ; $ fields [ $ operation -> field -> getName ( ) ] = $ operation -> field ; $ op = static :: createObject ( [ 'name' => $ this -> name , 'fields' => $ fields , 'meta' => $ this -> getMeta ( ) , 'extends' => $ this -> extends , ] ) ; $ op -> setAppLabel ( $ this -> getAppLabel ( ) ) ; return [ $ op , ] ; } } return parent :: reduce ( $ operation , $ inBetween ) ; }
Return either a list of operations the actual operation should be
replaced with or a boolean that indicates whether or not the specified
operation can be optimized across.

@param Operation   $operation
@param Operation[] $inBetween

@return mixed

@since  1.1.0

@author Eddilbert Macharia (http://eddmash.com) <edd.cowan@gmail.com>
Return either a list of operations the actual operation should be replaced with or a boolean that indicates whether or not the specified operation can be optimized across .