the other person could be declared legal guardian before hand.

edit: and well even if they were married but had kids by different parental partners, the biological parents have legal right in almost all cases.