
781 P.2d 799 (1989)
109 N.M. 71
ARMENDARIS WATER DEVELOPMENT COMPANY, Plaintiff-Appellee,
v.
RALPH H. RAINWATER, R & H Enterprises, Defendants-Appellants, and
Miller & Associates, Ltd., Defendant.
No. 10526.
Court of Appeals of New Mexico.
September 7, 1989.
*801 Ruth M. Schifani, Modrall, Sperling, Roehl, Harris & Sisk, P.A., Albuquerque, for plaintiff-appellee.
Anthony F. Avallone, Law Systems of Las Cruces, P.A., Las Cruces, for defendants-appellants.

OPINION
MINZNER, Judge.
Appellants Ralph M. Rainwater and R & H Enterprises appeal from a decision of the district court foreclosing various liens and ordering the sale of a ranch originally owned by Rainwater, title to which is now held by R & H Enterprises. Their appeal raises questions about the rights of the beneficiary of a purchase money resulting trust, when judgment lien creditors of the trustee sue to foreclose their liens against the trustee. We reverse and remand for further proceedings.

BACKGROUND.
R & H Enterprises is a trust of which Rainwater and a friend, Clifford Hammond, are co-trustees and the sole beneficiaries. One of Rainwater's judgment lien creditors sued him, R & H Enterprises, and several other creditors who held judgment liens against Rainwater, on the theory that Rainwater held legal title to the ranch prior to the time he transferred it to the trust. Appellants contended at trial that the liens did not attach because Rainwater had acquired title to the ranch on resulting trust for R & H Enterprises. The district court found that appellants had failed to prove Rainwater accepted title only for R & H Enterprises and ordered a sale of the ranch and distribution of the proceeds to the judgment lien creditors in order of priority. After judgment was entered and prior to the sale, the original plaintiffs assigned all their right, title and interest to appellee, Armendaris Water Development Company, who then purchased the property at the foreclosure sale. Appellee ultimately acquired the interests of the other creditors and moved this court to restyle the case. We granted the motion.
The record indicates that the ranch originally belonged to Rainwater and his wife as community property. She went through bankruptcy proceedings, but he did not. Sometime prior to the present action, Rainwater and his wife divorced.
In settling the bankruptcy estate of Rainwater's wife, the bankruptcy court ordered the sale of the ranch. Pursuant to 11 U.S.C. Section 363(f) and (h) (1982), the court ordered the sale free and clear of liens. As co-owner of the ranch, Rainwater was entitled to purchase it at a price equal to the highest price bid. See 11 U.S.C. § 363(i). This right is generally referred to as the right of first refusal. Appellee's predecessors in interest participated in the bankruptcy proceedings, but there is no evidence in the record that they entered into any written agreement concerning the sale.
Because Rainwater was unable to meet the highest price bid, Hammond agreed to provide the purchase price. Rainwater and *802 Hammond entered into written trust agreements. Rainwater agreed to assign his right of first refusal and his interest as co-owner to a trust; Hammond agreed to transfer the sum due the bankruptcy trustee to the trust. The name of the trust was R & H Enterprises. Under the terms of the trust agreements, Hammond had the right "to designate" all of the beneficial interest in R & H Enterprises until Rainwater paid Hammond one-half of the sum due the bankruptcy trustee plus interest. Thereafter, each would have the right "to designate" one-half of the beneficial interest. Rainwater was to manage the ranch, run and tend his cattle, and pay R & H Enterprises certain monthly charges based on the cattle tended during that period. By a separate document, Rainwater assigned his interest in the ranch to R & H Enterprises.
Rainwater asked the bankruptcy court to order the bankruptcy trustee to issue a deed to R & H Enterprises. Rainwater was concerned that his creditors, whose claims had not been satisfied in the bankruptcy proceedings, would seek to foreclose their liens if he received title directly. The court refused, and the bankruptcy trustee deeded the ranch to Rainwater. He in turn immediately deeded the ranch to R & H Enterprises. A few days later the present action was instituted. Appellants moved to add Hammond as a party, on the ground that he held a purchase mortgage on the ranch. The motion was denied.

DISCUSSION.
Appellants argue that when Rainwater received title from the bankruptcy trustee he acquired only legal title, and the beneficial interest belonged to R & H Enterprises. They contend that Rainwater had no interest in the ranch to which the judgment liens attached and that the district court erred in ordering foreclosure and sale on behalf of his creditors. See McCord v. Ashbaugh, 67 N.M. 61, 352 P.2d 641 (1960).
For the reasons that follow, we conclude Hammond was an indispensable party to the foreclosure action because his rights were affected by the judgment ordering foreclosure, and his rights differed from those of Rainwater and R & H Enterprises. See SCRA 1986, 1-019(A)(2). Because Hammond should have been made a party and was not, the trial court was without jurisdiction to proceed in his absence. Sellman v. Haddock, 62 N.M. 391, 310 P.2d 1045 (1957), overruled on other grounds, Safeco Ins. Co. v. U.S. Fidelity & Guar. Co., 101 N.M. 148, 679 P.2d 816 (1984). As has been stated in a leading treatise,
[g]enerally, the beneficiary [of a trust] is held not to be a necessary party. The earlier equity rule was that the beneficiary was always a necessary party, but the present position of the courts is that the trustee may represent the beneficiary in all actions relating to the trust, if rights of the beneficiary as against the trustee, or the rights of the beneficiaries among themselves, are not brought into question.
G. Bogert & G. Bogert, The Law of Trusts and Trustees § 593 at 421-2 (Rev.2d ed. 1980). Here, both co-trustees were required to be joined. See generally Annotation, Trust Beneficiaries as Necessary Parties to Action Relating to Trust or Its Property, 9 A.L.R.2d 10 (1950); Annotation, Who Must Be Joined in Action as Person "Needed for Just Adjudication" Under Rule 19(a), Federal Rules of Civil Procedure, 22 A.L.R.Fed. 765 (1975). Although appellants did not make this argument on appeal, failure to add an indispensable party is jurisdictional, and the court may consider it sua sponte. Sellman v. Haddock. Thus, the judgment and order must be reversed, and the cause remanded with instructions to add Hammond as a party defendant. We now address the resulting trust argument.
A resulting trust is a type of implied trust, recognized in a number of situations as a device to effect intent. For example, when property is taken in the name of one person, but another person provides the purchase price, the person holding legal title may be said to hold that title on resulting trust for the person who provided the funds with which the property was purchased. See McCollum v. McCollum, *803 202 Ga. 406, 43 S.E.2d 663 (1947); Godzieba v. Godzieba, 393 Pa. 544, 143 A.2d 344 (1958). This resulting trust is described as a purchase money resulting trust. See generally G. Bogert, Trusts § 74 (6th ed. 1987). This resulting trust does not arise if the person by whom the purchase price is paid manifests an intention that no resulting trust should arise. Restatement (Second) of Trusts § 441 (1959). It also does not arise if the policy against unjust enrichment is outweighed by the policy against giving relief to a person who has entered an illegal transaction. Id. at § 444. We believe that a transaction that is against public policy should be treated like an illegal transaction. Thus, a resulting trust would not arise if recognition of the trust would be against public policy.
The record indicates that Hammond, on behalf of R & H Enterprises, advanced the funds necessary for Rainwater to exercise the right of first refusal, but title was taken in Rainwater's name. On these facts, an inference arises that the beneficial interest did not belong to the person to whom legal title was transferred. See Browne v. Sieg, 55 N.M. 447, 234 P.2d 1045 (1951). Rather, there is an inference that the beneficial interest belonged to R & H Enterprises. In this case, there is no evidence of a contrary intent.
Where there is evidence of an express agreement consistent with the inference of a purchase money resulting trust, then that evidence will not defeat the claim to a resulting trust. Here, we have evidence of an agreement between the parties that R & H Enterprises would ultimately hold legal title. We view the agreement as strengthening the presumption that Rainwater received title to the ranch on behalf of R & H Enterprises. See Viner v. Untrecht, 26 Cal.2d 261, 158 P.2d 3 (1945); McCollum v. McCollum; Godzieba v. Godzieba.
Nevertheless, under the trust agreements, the beneficiaries of R & H Enterprises are the person who advanced the purchase price and the person in whose name title was acquired. Under these circumstances, it is necessary to identify the beneficial interests in the trust in order to evaluate appellants' resulting trust argument. In other words, it is necessary to consider the substance of what occurred rather than the form. Considering the substance rather than the form, we see no reason why appellee's liens would not have attached to the legal title acquired by Rainwater to the extent he had a beneficial interest in R & H Enterprises. To this extent, we disagree with appellants' theory on appeal. To the extent Hammond had a beneficial interest, however, we agree that Rainwater would have held only legal title; and appellee's liens would not have attached. See McCord v. Ashbaugh.
The trust agreements indicate that the parties intended Hammond would own a one-half undivided interest. As to this portion of the beneficial interest, the agreement proven is identical with that implied by law. We conclude the evidence would support a finding that a resulting trust for the benefit of Hammond arose as to one-half interest at the time Rainwater acquired the ranch.
The trust agreements also indicate that Rainwater had the opportunity to purchase a one-half undivided beneficial interest for a period of three years. He also had other rights under the trust, such as the right to manage the ranch. At oral argument, the parties advised the court that Rainwater was entitled to one-half of the proceeds of the bankruptcy sale but had not yet received them. We conclude the evidence supports an inference that Hammond gave Rainwater an unsecured, short-term loan with the expectation that Rainwater would be able to purchase a one-half undivided interest with his share of the bankruptcy sale proceeds. If the trial court finds Hammond made an unsecured loan, Rainwater would have acquired a one-half beneficial interest in his own name at the time of the transfer from the bankruptcy trustee, and the judgment liens would have attached to that interest. There would be no basis for a resulting trust as to this half. See Lifemark Corp. v. Merritt, 655 S.W.2d 310 (Tex. Ct. App. *804 1983); G. Bogert, supra, at 273-74; see also Restatement, supra, at § 441 comment f.
Appellee argues that the right of first refusal is a personal right, which Rainwater could not assign. It contends that this court ought not enforce the express trust, because enforcement would circumvent the purpose of Section 363(h). Appellee also argues that because Rainwater retained some beneficial interest in the trust, such as the right to live at and work the ranch, this court cannot treat him as a "straw" or nominal owner. Finally, appellee argues that appellants' theory is against public policy, because it would permit Rainwater to evade his creditors. We now address each of these arguments.
Although Rainwater attempted to assign his right of first refusal, under the findings of the district court the assignment was not effective. Appellants do not challenge the court's findings. Therefore, we assume, but do not decide, that the right was personal and not assignable. We agree with appellee's related argument that if the express trust circumvents the purpose of Section 363(h) it should not be enforced. However, we are not convinced from the record before us that the purpose of that section has been circumvented by the express trust or that recognition of a resulting trust would be contrary to public policy.
The record reveals no evidence that Hammond would have purchased the property at the bankruptcy sale for himself. Rather, the evidence suggests that the trust agreements were intended to permit Rainwater to exercise his right of first refusal by acquiring a new co-owner for one-half of the beneficial interest and obtaining short-term financing for the other one-half interest. There is nothing in Section 363(h) that directly prohibits such financing, and we decline to imply such a policy. However, if the court on remand finds that Hammond's "financing" was an attempt to acquire the property by circumventing the bidding process in the bankruptcy sale, see In re Fehl, 19 B.R. 310 (N.D.Cal. 1982), then it also may conclude that the policy against unjust enrichment is outweighed by public policy. Under those circumstances, it would be inappropriate to recognize a resulting trust. See Restatement, supra, at § 444.
We agree with appellee's contention that Rainwater was not a nominal owner. However, the interest of the beneficiary of a resulting trust is in direct relationship to the proportional part of the consideration paid. Wimberly v. Kneeland, 293 S.W.2d 526 (Tex. Ct. App. 1956). The party attempting to prove the existence of a resulting trust need not show that the alleged trustee has no beneficial interest. See id. Consequently, Rainwater's beneficial interest under the trust does not preclude the recognition of a resulting trust as to Hammond's beneficial interest.
The case law supporting appellee's final argument concerns debtors who furnish funds to purchase property in the name of another person in an attempt to evade their own creditors. See 4 J. Pomeroy, Equity Jurisprudence § 1043 (5th ed. 1941). That situation is not analogous to the present one. Appellee is entitled to reach Rainwater's interest in the ranch. The liens were of record, and Rainwater's beneficial interest is subject to attachment by his creditors. See NMSA 1978, § 14-9-3 (Repl.Pamp. 1988). The trust is not a spend-thrift trust, and we doubt whether as a matter of public policy, Rainwater could have created a spend-thrift trust for his own benefit. See NMSA 1978, § 42-9-4. As to any beneficial interest in Rainwater, then, appellee's claims have priority over Hammond's rights as an unsecured creditor.
The same cannot be said for any interest for which Hammond paid and with respect to which Rainwater acquired the ranch on resulting trust for Hammond's benefit. As to that interest, Hammond's rights attached at the time of the transfer by the bankruptcy trustee and have priority over appellee's liens. We view Hammond's right to priority as comparable to those of a purchase money mortgagee. Cf. *805 Pinellas County v. Clearwater Fed. Sav. & Loan Ass'n, 214 So.2d 525 (Fla. Dist. Ct. App. 1968) (recognizing that a purchase money mortgagee has priority over prior and subsequent lien creditors).
Under the district court's decision, it appears that appellee satisfied its claims against Rainwater with property that belonged in whole or in part to Hammond. If so, Rainwater's lien creditors have been unjustly enriched. Appellants have argued for the imposition of a resulting trust, which is a remedy intended to prevent unjust enrichment. See Restatement, supra, at § 444. Hammond is a necessary party to the resolution of appellants' claims. Because he was not joined, the judgment entered below must be reversed, and the case remanded for further proceedings. We reverse and remand to require joinder of Hammond as co-trustee and beneficiary and to permit the district court to consider what portion of the beneficial interest belonged to Hammond.

CONCLUSION.
In this case, the district court ordered a sale of the entire ranch, in a proceeding to which Hammond was not a party. The sale was not limited to Rainwater's interest in the trust. Because Hammond is a necessary party and was not joined, we reverse the trial court's judgment ordering foreclosure, and we remand the case for joinder of Hammond as a party defendant and for a new trial on the merits. No costs are awarded.
IT IS SO ORDERED.
DONNELLY and ALARID, JJ., concur.
