(a) Persons having liens under the provisions of this division, on the same property, may join in the same action for the enforcement of their respective liens; and when there is such joinder, the court or jury trying the action must ascertain the amount due to each of the plaintiffs secured by the lien, and judgment must be rendered accordingly; but the failure of one or more of the plaintiffs to establish his or their liens shall not defeat a recovery by the others. The proceeds of the sale of the property levied on, if not sufficient to satisfy the demands of all the plaintiffs, shall be distributed, after payment of the costs, pro rata among them.
(b) When persons having such liens on the same property refuse, after notice in writing, to join in such action, the persons giving the notice may proceed without them on making affidavit of the fact of such notice and refusal; and notice of the levy of the attachment must be served on the persons refusing to join in the manner and within the time required for the service of such notice on the defendant; and such persons, either at the trial, or at any time prior thereto, on making affidavit setting forth all facts necessary to the creation of their liens, and the amounts thereof, may be made plaintiffs in the action, and the action shall then proceed as if commenced jointly by them with the original plaintiffs; but on their failure to thus join, the action shall proceed for the benefit of the original plaintiffs, who shall, in that event, be entitled to priority of satisfaction.