Matt,
Thanks for your reply.
Pretty much everything you listed below is correct. What I did not
know is the isPersisted flag is what tells transfer to insert or
update. I assumed since my clientID was in the event, and the
populateBean() method was setting it (which I confirmed), that since I
had a non-zero value in the clientID of the object, transfer would do
the update. For the heck of it, I did try and setIsPersisted("true")
but it errored out.
So the solution was to use:
oClientBean = oService.getClient(event.getValue("id", 0));
For the purpose of the archives, I was trying out the PU 36 templates
that come with coldbox, and this code was from the doSave() method.
Thanks
On Nov 22, 7:56 pm, "Matt Quackenbush" <[EMAIL PROTECTED]> wrote:
> I think you're misunderstanding how Transfer works.
>
> The snippet you've posted shows that the first thing you're doing is asking
> your Service for a bean with an ID of 0. I don't know what your Service
> layer is doing to grab the bean and return it, but presumably it is asking
> Transfer for a Client bean with an ID of 0. Something like...
>
> <cffunction name="getClient">
> <cfargument name="id" />
>
> <cfreturn transfer.get("client", arguments.id) />
> </cffunction>
>
> If that is essentially what is going on, then I would expect that you would
> get a **new** Transfer object - that is, an empty object - back from
> Transfer. If a matching record is not found in the database, Transfer will
> return a new object.
>
> The next thing you're doing is populating the bean. ColdBox's
> populateBean() method from the IoC plugin simply populates the bean with
> data that is found in the request collection. It has nothing to do with
> Transfer or your database at all.
>
> Run this code:
>
> oClientBean = oService.getClient(0);
> getPlugin("beanFactory").populateBean(oClientBean);
> t = getPlugin("ioc").getBean("transfer").getTransfer();
> if ( NOT oClientBean.getIsPersisted() ) {
> dump("HOLY COW! IT'S A HOME RUN!");
> abort();}
>
> t.save(oClientBean);
>
> I'm betting that the code above will result in HOLY COW! IT'S A HOME RUN!
> being displayed to your screen. Why? Because you asked Transfer for an ID
> that does not exist, and you got a *new* object back from Transfer. You can
> populate that object with as much "real" data as you want, but it will
> _always_ be a new (unpersisted) TransferObject.
>
> Now then, presumably in your request collection you've got the ID for the
> bean you're actually looking for. If that's the case, note the subtle
> differences in the following snippet, and give it a try.
>
> oClientBean = oService.getClient(event.getValue("id", 0));
> getPlugin("beanFactory").populateBean(oClientBean);
> t = getPlugin("ioc").getBean("transfer").getTransfer();
> if ( oClientBean.getIsPersisted() ) {
> dump("YAY! I'M A REAL BOY!");
> abort();}
>
> t.save(oClientBean);
>
> HTH
--~--~---------~--~----~------------~-------~--~----~
Before posting questions to the group please read:
http://groups.google.com/group/transfer-dev/web/how-to-ask-support-questions-on-transfer
You received this message because you are subscribed to the Google Groups
"transfer-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/transfer-dev?hl=en
-~----------~----~----~----~------~----~------~--~---