TypeError: Cannot read property ‘adapter’ of undefined in Batch

Hi

I am getting a weird error in CloudCode using a DB.Batch operation.

TypeError: Cannot read property ‘adapter’ of undefined. Below is my code, and it seems to fail on the forEach line

    const job = await DB.job.first();
    if (job) {
        const batch = new DB.Batch();
        const shutdowns = await job.shutdowns.toArray();
        shutdowns.forEach(batch.destroy);
        batch.destroy(job);
        await batch.execute();
    }

Update your forEach to the following:

shutdowns.forEach((shutdown) => 
    batch.destroy(shutdown)
);

In the current setup, the batch.destroy will just give you a reference to the generic method and it is not tied to the specific batch.