It’s probably even worse than you think. The idea of a primary is for people to vote for who they want to be a candidate for their chosen party. Unfortunately you can get up to all kinds of shenanigans. You’re not obligated to vote in the election for the person you voted for in the primary. Since Trump was going to be his parties nominee and not be challenged in a primary he encouraged Republicans to register as Democrats and vote for a weak candidate to run against him in the actual election. Democrats have also registered as Republicans to block Trump nominees.