Cake\ORM\Association\BelongsToMany::_checkPersistenceStatus PHP Method

_checkPersistenceStatus() protected method

Throws an exception should any of the passed entities is not persisted.
protected _checkPersistenceStatus ( Cake\Datasource\EntityInterface $sourceEntity, array $targetEntities ) : boolean
$sourceEntity Cake\Datasource\EntityInterface the row belonging to the `source` side of this association
$targetEntities array list of entities belonging to the `target` side of this association
return boolean
    protected function _checkPersistenceStatus($sourceEntity, array $targetEntities)
    {
        if ($sourceEntity->isNew()) {
            $error = 'Source entity needs to be persisted before proceeding';
            throw new InvalidArgumentException($error);
        }
        foreach ($targetEntities as $entity) {
            if ($entity->isNew()) {
                $error = 'Cannot link not persisted entities';
                throw new InvalidArgumentException($error);
            }
        }
        return true;
    }