Dan, Basically you have to insure that your record knows if it's an update/insert you're trying to achieve. With your code, load method would allow you or using <cfset userRecord.setUserid(0)> because the save() method in your userDao will check that value. Since you skip that part with your <cfif > statement, your userId is set to any value you used before(edited some other user).
Gateways are just fine to be created in the application scope. João Fernandes -----Original Message----- From: [EMAIL PROTECTED] on behalf of Dan Vega Sent: Sat 08-Jul-06 2:56 PM To: [email protected] Subject: Re: [Reactor for CF] Related Objects Overwrite previous recorrd wow, so no matter what I should call the load method before save()? Even if its zero i still need to call this method? So using an Application template should i place reactor into the application scope in the onApplicationStart and then just create the records or gateways when i need them? This sounds like it may add a lof of "extra" processing to my application, does anyone have an example of how they do this? On 7/8/06, João Fernandes <[EMAIL PROTECTED]> wrote: > > Dan, > Quick reply, > > First as others already mentioned, you souldn't keep your record object in > the application scope. > > You were overwriting your previous record because you never invoked the > load() method in your userRecord so if you had updated an record and then > submited your form to create a new one, the record object would be the same > (the updated one) . > If you used <cfset application.UserRecord.load(UserId=form.UserId)> you > will insure that your UserRecord was loaded to a existing record or a blank > one (in case the id = 0). > > > João Fernandes > > > -----Original Message----- > From: [EMAIL PROTECTED] on behalf of Dan Vega > Sent: Sat 08-Jul-06 5:09 AM > To: [email protected] > Subject: Re: [Reactor for CF] Related Objects Overwrite previous recorrd > > Ok, so I have found the root of the problem but still dont understand why > its happening. I noticed that if I reinitialized my app (re instantiate my > applicatiton objects) that it was working. So I changed my code in the > form > submission to what you see below. Now there is no application variable and > its working fine. Im not sure why this is happening still but ill keep > digging? > > > > <cfif structKeyExists(form,"submit")> > > <cfset reactor = CreateObject("Component", "reactor.reactorFactory > ").init(expandPath("reactor.xml"))> > <cfset UserRecord = reactor.createRecord("users")> > > > <cfif form.userId NEQ "0"> > <!--- this lets us know we are updating an existing record, if 0 > add > new record ---> > <cfset UserRecord.setUserId(form.UserId)> > </cfif> > > <cfset UserRecord.setUsername(form.username)> > <cfset UserRecord.setPassword(form.password)> > <cfset UserRecord.setEmailAddress(form.emailaddress)> > <cfset UserRecord.setFname(form.fname)> > <cfset UserRecord.setLname(form.lname)> > > <!--- validate the user ---> > <cfset UserRecord.validate() /> > <cfset errorCollection = UserRecord._getErrorCollection() /> > > > <cfif NOT ErrorCollection.hasErrors()> > <!--- save the user and redirect to their view ---> > <cfset UserRecord.save()> > <cflocation URL="users.cfm" addtoken="false"/> > </cfif> > > </cfif> > > > On 7/8/06, Matthew Darby <[EMAIL PROTECTED]> wrote: > > > > I don't see where having userid set to 0 should be a problem. In fact > > reactor should automatically be setting your TO object for the userid to > 0 > > as a default value. Then MySQL would use auto increment to to set the > > primary key for the next value if it is set on the column userid as > long as > > the . So as long as there isn't a custom method that is overriding the > > save method in the record object during this call: <cfset > > application.UserRecord.save()> then I don't see how a previous record > gets > > overwritten without that previous records' id being set prior to the > call. > > > > > > On 7/7/06, Dan Vega <[EMAIL PROTECTED]> wrote: > > > > > If I update the user it works fine, it is only upon insert of a new > > record that I am seeing this. I am also logging getUserId() before the > save > > method is called and it is set to 0 > > > > Is there a way to clear this so it is null? Should I be doing this > > > > > > <cfif form.userId NEQ "0"> > > <!--- this lets us know we are updating an existing record, if 0 > > add new record ---> > > <cfset application.UserRecord.setUserId (form.UserId )> > > <cfelse> > > <cfset application.UserRecord.setUserId()> > > </cfif> > > > > Instead of this > > > > > > > > <cfif form.userId NEQ "0"> > > <!--- this lets us know we are updating an existing record, if 0 > > add new record ---> > > <cfset application.UserRecord.setUserId(form.UserId)> > > </cfif> > > > > On 7/7/06, Matthew Darby < [EMAIL PROTECTED]> wrote: > > > > > Dan, I am must say I am kind of stumped. I am not sure why removing > > > your relationships would allow for the code to work either. I am > assuming > > > with the bit of code you provided that you are expecting to only > update the > > > user table so you are not doing anything in the group or user_group > tables > > > yet. Maybe someone else has some opinions about areas we haven't > explored > > > yet. > > > > > > On 7/7/06, Dan Vega <[EMAIL PROTECTED]> wrote: > > > > > > > Thats what I thought was happening as well but i am logging > > > > form.userId before and after. That setUserId(form.userId) method is > > > > never being called so it should just auto increment. > > > > > > > > On 7/7/06, Matthew Darby <[EMAIL PROTECTED]> wrote: > > > > > > > > > You are right about that, I wasn't sure at first if you needed it. > > > > > One thing I am wondering is though whenever you are performing the > add > > > > > process for the user are you sure that the userid is 0? Or is the > form > > > > > carrying over the previous userid? I know it sounds silly, but > for right > > > > > now with what code you have presented its the first question that > comes to > > > > > mind. > > > > > > > > > > On 7/7/06, Dan Vega < [EMAIL PROTECTED]> wrote: > > > > > > > > > > > So the field tag makes alot of sense and should be used but i > dont > > > > > > think thats my problem here. I am usin MySQL 5x as well. > > > > > > > > > > > > On 7/7/06, Dan Vega < [EMAIL PROTECTED]> wrote: > > > > > > > > > > > > > Yes, all three tables have a primary key set. I will start > > > > > > reading on the field tag now, is my code wrong? > > > > > > > > > > > > On 7/7/06, Matthew Darby < [EMAIL PROTECTED]> wrote: > > > > > > > > > > > > > Dan, > > > > > > > > > > > > Does your database tables have a primary key set? Also, you > might > > > > > > want to read up on Doug's documentation on the field tag when > defining your > > > > > > objects for reactor. > > > > > > > > > > > > > > > > > > On 7/7/06, Dan Vega <[EMAIL PROTECTED]> wrote: > > > > > > > > > > > > > > PLEASE ANYONE!!! :) > > > > > > > > > > > > > > I'm sorry if i bothered anyone with the validation question, I > > > > > > > just searched the archives and found my answer. I do have a > problem though. > > > > > > > > > > > > > > I have users,groups and a users_groups table which ties the 2 > > > > > > > together. Here is what my config file looks like > > > > > > > > > > > > > > > > > > > > > <object name="users"> > > > > > > > <hasMany name="groups"> > > > > > > > <link name="users_groups"/> > > > > > > > </hasMany> > > > > > > > </object> > > > > > > > > > > > > > > <object name="groups"> > > > > > > > <hasMany name="users"> > > > > > > > <link name="users_groups"/> > > > > > > > </hasMany> > > > > > > > </object> > > > > > > > > > > > > > > <object name="users_groups"> > > > > > > > <hasOne name="users"> > > > > > > > <relate from="userId" to="userId"/> > > > > > > > </hasOne> > > > > > > > <hasOne name="groups"> > > > > > > > <relate from="groupId" to="groupId"/> > > > > > > > </hasOne> > > > > > > > </object> > > > > > > > > > > > > > > > > > > > > > With this configuration in place, if I try and add a user it > > > > > > > overwrites the previous record. If I take this out It allows > me to keep > > > > > > > adding users. Why would these relationships > > > > > > > overwrite in the database? Below is the code where the user is > > > > > > > added. > > > > > > > > > > > > > > > > > > > > > <cfif structKeyExists(form,"submit")> > > > > > > > > > > > > > > <cfif form.userId NEQ "0"> > > > > > > > <!--- this lets us know we are updating an existing > > > > > > > record, if 0 add new record ---> > > > > > > > <cfset application.UserRecord.setUserId(form.UserId)> > > > > > > > </cfif> > > > > > > > > > > > > > > <cfset application.UserRecord.setUsername(form.username)> > > > > > > > <cfset application.UserRecord.setPassword (form.password)> > > > > > > > <cfset application.UserRecord.setEmailAddress( > > > > > > > form.emailaddress)> > > > > > > > <cfset application.UserRecord.setFname(form.fname)> > > > > > > > <cfset application.UserRecord.setLname(form.lname )> > > > > > > > > > > > > > > <!--- validate the user ---> > > > > > > > <cfset application.UserRecord.validate() /> > > > > > > > <cfset errorCollection = > > > > > > > application.UserRecord._getErrorCollection() /> > > > > > > > > > > > > > > > > > > > > > <cfif NOT ErrorCollection.hasErrors()> > > > > > > > <!--- save the user and redirect to their view ---> > > > > > > > <cfset application.UserRecord.save()> > > > > > > > <cflocation URL="users.cfm" addtoken="false"/> > > > > > > > </cfif> > > > > > > > > > > > > > > </cfif> > > > > > > > > > > > > > > -- > > > > > > > Dan Vega > > > > > > > [EMAIL PROTECTED] > > > > > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > > > > > > > -- -- -- -- -- -- > > > > > > > Reactor for ColdFusion Mailing List > > > > > > > [email protected] > > > > > > > Archives at: > http://www.mail-archive.com/reactor%40doughughes.net/ > > > > > > > > > > > > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > > > > > > > -- -- -- -- -- -- > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > Matt D. > > > > > > http://matthewdarby.com > > > > > > > > > > > > > > > > > > > > > > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- > > > > > > -- -- -- -- -- > > > > > > Reactor for ColdFusion Mailing List > > > > > > [email protected] > > > > > > Archives at: > http://www.mail-archive.com/reactor%40doughughes.net/ > > > > > > > > > > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- > > > > > > -- -- -- -- -- > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > Dan Vega > > > > > > [EMAIL PROTECTED] > > > > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- > > > > > > -- -- -- -- -- > > > > > > Reactor for ColdFusion Mailing List > > > > > > [email protected] > > > > > > Archives at: > http://www.mail-archive.com/reactor%40doughughes.net/ > > > > > > > > > > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- > > > > > > -- -- -- -- -- > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > Dan Vega > > > > > [EMAIL PROTECTED] > > > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- > > > > > -- -- -- -- > > > > > Reactor for ColdFusion Mailing List > > > > > [email protected] > > > > > Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ > > > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- > > > > > -- -- -- -- > > > > > > > > > > > > > > > > > > > > > -- > > > > Matt D. > > > > http://matthewdarby.com > > > > > > > > > > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > > > > -- -- -- -- > > > > Reactor for ColdFusion Mailing List > > > > [email protected] > > > > Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ > > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > > > > -- -- -- -- > > > > > > > > > > > > > > > > -- > > > Dan Vega > > > [EMAIL PROTECTED] > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- > > > -- -- -- > > > Reactor for ColdFusion Mailing List > > > [email protected] > > > Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- > > > -- -- -- > > > > > > > > > > > -- > > Matt D. > > http://matthewdarby.com > > > > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- > > -- -- > > Reactor for ColdFusion Mailing List > > [email protected] > > Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- > > -- -- > > > > > > > > -- > > Dan Vega > > [EMAIL PROTECTED] > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- > > -- -- > > Reactor for ColdFusion Mailing List > > [email protected] > > Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- > > -- -- > > > > > > > > -- > > Matt D. > > http://matthewdarby.com > > > > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- > > -- -- > > Reactor for ColdFusion Mailing List > > [email protected] > > Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- > > -- -- > > > > > > -- > Dan Vega > [EMAIL PROTECTED] > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- -- > Reactor for ColdFusion Mailing List > [email protected] > Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- -- > > > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- -- > Reactor for ColdFusion Mailing List > [email protected] > Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- > -- -- > > -- Dan Vega [EMAIL PROTECTED] -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Reactor for ColdFusion Mailing List [email protected] Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Reactor for ColdFusion Mailing List [email protected] Archives at: http://www.mail-archive.com/reactor%40doughughes.net/ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
<<winmail.dat>>
