Frage

I'm trying to run a very quick update query to record that a user's email address is confirmed (setting the confirmed [bit] column in my users table to 1 after they click a link sent via email). Here's the action that should do it:

    <cffunction name="confirmEmail">
    <cfscript>
      user = model("user").findOne(where="id=#params.userid# AND uuid='#params.uuid#'", returnAs="query");
      if(user.recordCount) {
        pageTitle = "E-mail Confirmation Success";
        user.update(confirmed=1);
      } else {
        redirectTo(route="authenticationDenied", alert="Something was wrong with your confirmation string. Please contact site administrators.");
      }
    </cfscript>
  </cffunction>

But when I submit the appropriate URL (I've dumped and can see the model call finds one valid record), I get the following error in Railo 3.3.x:

No matching Method/Function [update] for call with named arguments found

...highlighting the user.update(confirmed=1); line in my code. So what am I doing wrong? Previously I have always used save/update(params.user) or thereabouts for these queries, but that seems like overkill here; I just want to pass a 1-bit update.

War es hilfreich?

Lösung

Okay, my CTO who is new to CFML and Wheels figured this out in like 5 seconds. Hence the "C" I guess.

By returning the user model as a query instead of an object, I didn't have access to the update/save() methods. (Duh, MVC n00b.) The reason I was returning it as a query was simply that I've been doing that a fair bit in order to have easy manipulation of output, and in this case so that I can test for the existence of a record the way I always have (if recordCount). But this works...

  <cffunction name="confirmEmail">
    <cfscript>
      user = model("user").findOne(where="id=#params.userid# AND uuid='#params.uuid#'");
      if(isObject(user)) {
        user.update(confirmed="1");
      } else {
        flashInsert(error="Something was wrong with your confirmation string. Please contact site administrators.");
        redirectTo(route="authenticationDenied");
      }
    </cfscript>
  </cffunction>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top