Investors & landlords

How does someone buy a home with a heloc that is associated with that home? You can’t buy a home from yourself. Can you use a heloc on an investment property to buy your new primary? Would this be deductible?