What is the psychology behind people who are attracted to people who are no good for them?

And how do they break the pattern?