Lucee ORM没有数据源会话

时间:2016-02-02 07:33:42

标签: orm coldfusion lucee

我正在尝试在Lucee服务器中使用ORM,但继续收到错误there is no Session for the datasource [mydatasource]。数据源确实存在并且连接正常工作,在管理员中进行验证并使用cfquery进行测试。

以下是application.cfc

<cfcomponent>

<cffunction name="onRequestStart" access="public" returntype="boolean" output="false">
    <cfset this.datasource = "rift" />
    <cfset this.ormEnabled = true />
    <cfsetting showdebugoutput="false" />
    <cfset this.ormsettings = { } />
    <!---<cfset this.ormsettings.dbcreate = "dropcreate" />--->
    <cfset this.ormsettings.logSQL = true />
    <cfset ORMReload() />
    <cfset testquery = ORMExecuteQuery("from test")>
    <cfreturn true />
</cffunction>

</cfcomponent>

1 个答案:

答案 0 :(得分:4)

ORMSettings应该在伪构造函数中定义,所以我相信这就是造成这个问题的原因。

<cfcomponent output="false">

    <!--- define orm settings --->
    <cfset this.datasource = "rift" />
    <cfset this.ormEnabled = true />
    <cfset this.ormsettings.logSQL = true />


    <cffunction name="onRequestStart" access="public" returntype="boolean" output="false">
        <cfif StructKeyExists(url, "reload")>
            <!--- you don't want to do this on every request --->
            <cfset ORMReload() />
        </cfif>
        <cfset testquery = ORMExecuteQuery("from test")>
        <cfreturn true />
    </cffunction>

</cfcomponent>

另外,请确保您已将cfc命名为test.cfc,并将其设置为持久性。