如何使Coldfusion Reactor忽略表中的某些列

时间:2018-12-11 08:16:13

标签: orm coldfusion coldfusion-10 reactor

我在项目中使用Coldfusion 10 + Reactor。我添加了一个新的TIMESTAMP字段,该字段将自动更新为CURRENT_TIMESTAMP。当这个新字段未包含在Reactor对象中时(例如,道,到,记录。但是一旦重新生成ColdFusion对象,它将失败。

那我该如何忽略反应堆中的新字段?

这是相关代码

<object name="Object">
    <hasOne name="XXXX">
        <relate from="KeyUUID" to="KeyUUID"/>
    </hasOne>
    ...
</object>

重新生成ColdFusion对象之后,ObjectDao.cfc中的create / update方法将包含我的新字段。 ReactD根据我的数据库表重新生成了ObjectDao.cfc。我想从Reactor对象中排除这个新字段,例如道,到,记录。

              

<cfquery name="qCreate" datasource="#_getConfig().getDsn()#" username="#_getConfig().getUsername()#" password="#_getConfig().getPassword()#">
    INSERT INTO #Convention.FormatObjectName(getObjectMetadata())#
    (
            ...
            #Convention.formatInsertFieldName('newField', 'Object')#

    ) VALUES (
            ...
            <cfqueryparam cfsqltype="cf_sql_timestamp"

            value="#arguments.to.newField#"

                null="#Iif(NOT Len(arguments.to.lastModifiedDBTime), DE(true), DE(false))#"
             /> 
    )
    ...
</cfquery>

1 个答案:

答案 0 :(得分:1)

我们现在通过更新ObjectDao.cfc来实现。

<cffunction name="readFields" access="private" hint="I populate the table with fields." output="false" returntype="void">
...
    <cfloop query="qFields">
        <cfset blnProcess = true />
        <cfif structKeyExists(stcFieldsToSkip,arguments.Object.getName())>
           <cfif qFields.FIELD EQ stcFieldsToSkip[arguments.Object.getName()]>
               <cfset blnProcess = false />
           </cfif>
        </cfif>
        <cfif blnProcess>
            <!---
            mod by SPJ: in MySql 4 tinytext, text, mediumtext and longtext don't report their maxlength value, so we
            have to set it by hand.  The field lengths were obtained from http://www.cs.wcupa.edu/~rkline/mysqlEZinfo/data_types.html#Storage_requirements
        --->
            <cfswitch expression="#qFields.TYPE#">
                ...
            </cfswitch>
            <!--- end mod by SPJ --->

            <!--- create the field --->
            ...

            <!--- add the field to the table --->
            <cfset arguments.Object.addField(Field) />
        </cfif>
    </cfloop>
</cffunction>