Issue with Insert the object fails - Oracle Database.

I have a getAll() function in these same objects and the handler calls it and it works fine. What am I doing wrong?

Handler: spoofUser.cfc

function insert(event){

var rc = event.getCollection();

// Page Title

rc.pageTitle = “Insert Page”;

// Instantiate the Spoofer Service

rc.oSpoof = populateModel(“spoofService”); // Put in RC just so when I comment out the

// insert I can see the object.

// Insert spoofee’s

rc.oSpoofee = rc.oSpoof.insertSpoofee(rc);

// Send to Spoof user Home

setNextEvent(event=‘spoofUser.index’);

// Set the View for this event (This will go away once the code is working.)

event.setView(“spoofUser/test”);

}

spoofService.cfc

/*

  • Insert

*/

public function insertSpoofee(event)

{

var oSpoof = createObject(‘component’, ‘spoof’);

var qResult = oSpoof.insertSpoofee(event=event,dsn=’#dsn.getName()#’);

return;

}

Spoof.cfc

INSERT INTO DEV_SPOOFER

(

SPOOFEE,

NPKE_TYPE,

NPKE_SUBJECT,

DESCRIPTION

)

VALUES

(

#RC.SPOOFEE#’,

#RC.NPKE_TYPE#’,

#RC.NPKE_SUBJECT#’,

#RC.DESCRIPTION#’

)

Hi Nathan,

I'm a bit confused by your code. In the spoofUser.cfc you have
populateModel("spoofService"); I think that should be
getModel("spoofService").

Next you have rc.oSpoof.insertSpoofee(rc); which is passing the
request collection to the spoofService.insertSpoofee method, but the
spoofService.insertSpoofee method is expecting the event object (not
the collection) as Spoof.insertSpoofee method has
event.getCollection() which is going to bomb.

- John

I had changed this code so many times I did not know where the errors were. I will try it with those changes.

This first issue I had was the Sequence for it so no matter what I did it would not have worked.

I am sure that is how I messed this up.

Is populateModel(“spoofService”); not working anymore as I had it work for my getAll() function.

Is this the new way to do it or am I understanding something incorrectly. getModel(“spoofService”).

Hi Nathan,

Services are usually singletons, so you typically inject them into the
handler and do something like:

component
{
  property name="UserService" inject="UserService";

  function foo(event)
  {
    var rc = event.getCollection();
    rc.User = MyService.getNewUser();
    // populate User will data from rc struct
    populateModel( rc.User );
    MyService.saveUser( rc.User );
  }
}

The saveUser method of the UserService would probably see if the user
already existed and then call either an insert or update. You could
choose to push all this logic deeper into the model if you wanted to.

Hope that helps.

populateModel will probably work, but it's really meant for popula