This works to attract flies because flies are attracted to the fermentation. Dish soap breaks the surface tension of the liquid, which the flies normally rely on to stay afloat, so that the flies will fall in and drown.