i think most recent games handle it somehow like this:
-unit a attacks everything within its range
-if there's no enemy with attack skill within range, but unit a gets attacked from outside its range:
-it will "call" units close to it to whom apply the same conditions (no enemy with attack skill in range)
-together they move in the direction of the attacking unit, attacking only units with an attack skill
-when they attacked a unit on their way, they will stop after they killed it and continue attacking everything within range
-this gets triggered again when the unit, that initially attacked unit a, attacks again
hope this is somehow understandable