public function saveMany($entities, $options = [])
    {
        $isNew = [];
        $cleanup = function ($entities) use (&$isNew) {
            foreach ($entities as $key => $entity) {
                if (isset($isNew[$key]) && $isNew[$key]) {
                    $entity->unsetProperty($this->getPrimaryKey());
                    $entity->isNew(true);
                }
            }
        };

        try {
            $return = $this->getConnection()
                ->transactional(function () use ($entities, $options, &$isNew) {
                    foreach ($entities as $key => $entity) {
                        $isNew[$key] = $entity->isNew();
                        if ($this->save($entity, $options) === false) {
                            return false;
                        }
                    }
                });
        } catch (\Exception $e) {
            $cleanup($entities);

            throw $e;
        }

        if ($return === false) {
            $cleanup($entities);

            return false;
        }

        return $entities;
    }