Search code examples
ormcoldfusionlucee

Lucee ORM there is no Session for the datasource


I am trying to work with ORM in Lucee server but continue to get the error there is no Session for the datasource [mydatasource]. The datasource does exist and the connection works, verified in the admin and tested with a cfquery.

Here is the 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>

Solution

  • ORMSettings should be defined in the pseudo-constructor, so I believe that is what is causing the issue for you.

    <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>
    

    Also make sure you have named your cfc test.cfc and it's is set to be persistent.