1

我正在尝试在 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>
4

1 回答 1

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>

还要确保您已命名您的 cfctest.cfc并将其设置为持久性。

于 2016-02-02T09:06:09.293 回答