Fix bug with referencing batch.Id before batch was saved to the database