質問

I've started using ORM in Coldfusion 9, but I'm running into an issue in which I've got a CFC that is set to persistant=true so that when I run myCFC.init() the default values of the properties are assigned - but I don't want to use this CFC with ORM.

The problem is that Coldfusion throws the error "Table myCFC defined for cfc myCFC does not exist."

Is there a way I can get my application to ignore certain CFCs? Or only pay attention to specific CFCs, other than persistant=true

Alternatively, can I get my default property values to take effect without making the component persistent

役に立ちましたか?

解決

Alternatively, can I get my default property values to take effect without making the component persistent?

Yes, just set them in your init() method.

<cfcomponent name="person" persistent="false" output="false">

 <cfproperty name="gender"><!--- Non-persistent CFC: you can't set a default here --->

 <cffunction name="init" output="false>
  <cfset variables.gender = "m"><!--- Set the default here --->
 </cffunction>

</cfcomponent>

You would also need to do this in your persistent CFCs for any complex or dynamic value defaults (e.g. an array or the current date), since you can only set simple default values (e.g. a literal string or integer) in property declarations.

<cfcomponent name="person" persistent="true" table="persons" output="false">

 <cfproperty name="gender" default="m"><!---Persistent CFC, so this simple default will be set --->
 <cfproperty name="dateCreated"><!---You can't set a default dynamic date value --->

 <cffunction name="init" output="false>
  <cfset variables.dateCreated= Now()><!--- Set the current datetime here --->
 </cffunction>

</cfcomponent>

他のヒント

Any code you place between your opening and the first will be executed. I'm assuming your using CFproperty tags to set you defaults. Instead, use this structure:

<cfcomponent name="aCFC">

    <!---
    || Psuedo Constructor code: this code runs when the object is created.
    ||--->

    <cfset defaultVar_1 = "default value">
    ...etc

    <cffunction name="firstFunction">
        ...
    </cffunction>
</cfcomponent>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top