If you are not married and buy a property with your partner, it is possible to set out how the money should be divided upon sale by entering into a Declaration of Trust.
However, if you are married or go on to get married, the strength of that Trust is considerably weakened as divorce courts have the power to vary or set them aside. Whilst a court will look at the Declaration of Trust when determining the final outcome, the terms contained within it may be outweighed by the welfare and housing needs of your partner (particularly if you have had children together).
The reason for this is that the divorce courts have wide powers when it comes to deciding financial settlements. The court will look at all of the circumstances of your particular case and it is usually the case that the family home is central to the marriage and the starting point for division of this will often be fifty-fifty even if you have Trust Deed or even if it is only owned by one person.
If you want to protect the money you have invested in a property, you would be best advised to turn your Trust Deed into a Pre or Post Nuptial Agreement.