protected function _onSaveSuccess($entity, $options)
    {
        $success = $this->_associations->saveChildren(
            $this,
            $entity,
            $options['associated'],
            ['_primary' => false] + $options->getArrayCopy()
        );

        if (!$success && $options['atomic']) {
            return false;
        }

        $this->dispatchEvent('Model.afterSave', compact('entity', 'options'));

        if ($options['atomic'] && !$this->getConnection()->inTransaction()) {
            throw new RolledbackTransactionException(['table' => get_class($this)]);
        }

        if (!$options['atomic'] && !$options['_primary']) {
            $entity->clean();
            $entity->isNew(false);
            $entity->setSource($this->getRegistryAlias());
        }

        return true;
    }
protected function _onSaveSuccess($entity, $options)
    {
        $success = $this->_associations->saveChildren(
            $this,
            $entity,
            $options['associated'],
            ['_primary' => false] + $options->getArrayCopy()
        );

        if (!$success && $options['atomic']) {
            return false;
        }

        $this->dispatchEvent('Model.afterSave', compact('entity', 'options'));

        if ($options['atomic'] && !$this->getConnection()->inTransaction()) {
            throw new RolledbackTransactionException(['table' => get_class($this)]);
        }

        if (!$options['atomic'] && !$options['_primary']) {
            $entity->clean();
            $entity->isNew(false);
            $entity->setSource($this->getRegistryAlias());
        }

        return true;
    }
protected function _onSaveSuccess ( $ entity , $ options ) { $ success = $ this -> _associations -> saveChildren ( $ this , $ entity , $ options [ 'associated' ] , [ '_primary' => false ] + $ options -> getArrayCopy ( ) ) ; if ( ! $ success && $ options [ 'atomic' ] ) { return false ; } $ this -> dispatchEvent ( 'Model.afterSave' , compact ( 'entity' , 'options' ) ) ; if ( $ options [ 'atomic' ] && ! $ this -> getConnection ( ) -> inTransaction ( ) ) { throw new RolledbackTransactionException ( [ 'table' => get_class ( $ this ) ] ) ; } if ( ! $ options [ 'atomic' ] && ! $ options [ '_primary' ] ) { $ entity -> clean ( ) ; $ entity -> isNew ( false ) ; $ entity -> setSource ( $ this -> getRegistryAlias ( ) ) ; } return true ; }
Handles the saving of children associations and executing the afterSave logic
once the entity for this table has been saved successfully.

@param \Cake\Datasource\EntityInterface $entity the entity to be saved
@param \ArrayObject $options the options to use for the save operation
@return bool True on success
@throws \Cake\ORM\Exception\RolledbackTransactionException If the transaction
is aborted in the afterSave event.
Handles the saving of children associations and executing the afterSave logic once the entity for this table has been saved successfully .