When it is adjudged that any of the defendants have a lien upon the property, the court shall make a like judgment in relation thereto and the debt secured thereby as if such defendant were a plaintiff in the action. When a judgment is given foreclosing two or more liens upon the same property or any portion thereof in favor of different persons not united in interest such judgment shall determine and specify the order of time, according to their priority, in which the debts secured by such lien shall be satisfied out of the proceeds of the sale of the property.