In every case such judgment shall be rendered upon the right of the defendant and also upon the right of the party alleged to be entitled, or only upon the right of the defendant, as justice may require. When the action shall not be terminated during the term of the office in controversy it may notwithstanding be prosecuted to completion and judgment rendered, which shall determine the right which any party had to the office, and to the fees and emoluments thereof.
NMS § 44-3-9