2016-02-02 24 views
1

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

这里是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> 
+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,它的设置是持久的。

+0

哈哈,甚至没有注意到! –

+0

感谢您的帮助,它现在正在为我工​​作。 – Silas