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="" 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/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --






-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
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/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Reply via email to