would this be better?
    <cfloop collection="#primaryKeys#" item="i">
        <!--- ajm: not record to read --->
        <cfif primaryKeys[i] NEQ "">
            <cfthrow message="no primary key value - new record">
        </cfif>   
        <cfinvoke component="#record#" method="set#i#">
            <cfinvokeargument name="#i#" value="#primaryKeys[i]#" />
        </cfinvoke>
           
    </cfloop>

relies on in genericRead()
         <cftry>
            <cfset result = getOrmAdapter().read(table, criteria) />
            <cfcatch>
                <cfset result = getOrmAdapter().new(table) />
            </cfcatch>
        </cftry>


On 10/19/06, AJ Mercer <[EMAIL PROTECTED]> wrote:
I have gotten to the bottom of this
   -\ModelGlue\unity\orm\ReactorAdapter.cfc  read()

The read function is loading blank values ito the primary key fields, thus over writting what was been set by the TO object.

I have put in a check so it will only set values if they are blank. This works but...then it will do a database read for a record that does not exist. I will look at a way so it will just return a new record if there are blank fields for the primary key - this could possible be done by the calling function genericRead() - which if receives and error from read() does the following:
    <cfset result = getOrmAdapter().new(table) />



<cffunction name="read" returntype="any" output="false" access="public">
    <cfargument name="table" type="string" required="true" />
    <cfargument name="primaryKeys" type="struct" required="true" />
   
    <cfset var i = "" />
    <cfset var record = new(arguments.table) />   

    <cfloop collection="#primaryKeys#" item="i">
<cfif primaryKeys[i] NEQ ""> <!--- ajm: dont set fields if blank - new record --->
        <cfinvoke component="#record#" method="set#i#">
            <cfinvokeargument name="#i#" value="#primaryKeys[i]#" />
        </cfinvoke>
</cfif>               
    </cfloop>

    <cfset record.load() />

    <cfreturn record />
</cffunction>





On 10/18/06, AJ Mercer < [EMAIL PROTECTED] > wrote:
UPDATE 2

I have hacked the edit.xsl to output and dump variables. Both my manual reactor calls and mg scaffold create the same object
namely:
    component translator.model.data.Record.TaskRecordmysql
    component translator.model.data.Record.taskRecordmysql

scaffold xsl is generating the following functions
    taskRecord.getid()               -> returns empty string
    taskRecord.getdescription()  -> returns default value set in TO object

The cfdump of the object has methods gor getID and getDescription

Below is the code from my manual reactor calls that does return the default value from getID()

<!--- create a userRecord --->
<cfset newtaskRecord = ajmReactor.createRecord("Task") />
ID before set: <cfdump var="#newtaskRecord.getID()#" label="ID before set"><br />
description before set: <cfdump var="#newtaskRecord.getDescription()#" label="description before set"><br />
<cfset newtaskRecord.setDescription("new record #now()#") />
<cfset newtaskRecord.setDone(0) />
<cfset newtaskRecord.setPRIORITY(3) />



On 10/18/06, AJ Mercer <[EMAIL PROTECTED]> wrote:
UPDATE

If I set up and call reactor manually, when I create a new record, it does pick up the values set in the TO object.

So it would seem the issue is in the scaffold...



On 10/18/06, AJ Mercer <[EMAIL PROTECTED]> wrote:
Perhaps I will try asking this in a different way...

How can I set the value for a primary key before a new record is inserted into the database?

eg 1, if the PK is varchar and I want to set it to createUUID()

or

eg 2, want to set the value to a user input - like their email address.





On 10/17/06, AJ Mercer < [EMAIL PROTECTED]> wrote:
MG:U | mySQL5 | apache | cfmx702

I have modified my object TO cfc to set default values. It works fine for a standard field, but not for my primary key field.

<cfset this.id = "ajm" />
<cfset this.description = "description goes here" />

The scaffold does it's thing and when I add a new record I see 'description goes here' in the 'description' field.

When I vew source, there is nothing in the hidden 'id' field.


Can some one please explain or point me in the correct direction.
TIA








-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Reactor for ColdFusion Mailing List
reactor@doughughes.net
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Reply via email to