Professor Kodama's Magnemite lives with him at his lab. It wasn't getting along with Quagsire so Professor Kodama decided to make a machine that would get them to like each other. Unfortunately it didn't work on either of them.
When the machine was stolen by Team Rocket, Quagsire used its Water Gun to project Magnemite really fast towards the balloon to stop Team Rocket. Magnemite cut the rope hanging from the balloon, breaking the machine in the process. Working together, Magnemite and Quagsire were able to start to patch things up between them.