You could plant radishes as a trap crop to lure the maggots away from your onions.