An ionic bond occurs when