protected function setLastIdWhere($entity, $criteria)
    {
        $sql = sprintf('SELECT id FROM %s WHERE %s', $entity, $criteria);
        $statement = $this->execute($sql);
        $this->throwErrorIfNoRowsAffected($statement);
        $result = $statement->fetchAll();

        if (! isset($result[0]['id'])) {
            throw new \Exception('Id not found in table.');
        }

        $this->debugLog(sprintf('Last ID fetched: %d', $result[0]['id']));
        $this->handleLastId($entity, $result[0]['id']);

        return $statement;
    }