Configure CF9 ORM Settings, based on ColdBox environment

So here is a bit of a fun one I’m trying to work out.

I have this in my Application.cfc:

//lets set up the ORM parts this.datasource = "mydatasource"; this.ormenabled = true; this.ormsettings = { cfclocation = "model" ,dbcreate = "dropcreate" ,dialect="MySQLwithInnoDB" ,flushatrequestend="false" ,logSQL=true };

The only thing is, I only want to use ‘dropcreate’, when I’m in my development environment (for obvious reasons)

Is there a way I can access what environment I am in during the initialisation of my Application.cfc?

I was thinking you could access the application.cfController directly, but it won’t have been created yet if it’s onApplicationStart().

I’ve got some more CF9 ORM integration questions coming, but I’ll leave this funky one with you for now.


Thanks Mark!!

Will start digesting now!! :slight_smile:


I have not tried this, but here is a question, is there a way to modify the application.cfc this variables from another component? Is there a way to reach them?

If not, we would have to pass the this reference somewhere in order to manipulate it at onApplicationStart once the interceptors have fired for the environment detection and put a reference on the RC maybe??

Nope, I don’t believe that you can modify them at all.

The Application.cfc variables have to be set before anything else can fire.


I think you can modify the THIS variables of another Application CFC.

Using this

applicationScopeTracker =
myApplicationScope =

If the SessionFactory has already been created at this stage (which I would expect that it has), then I would think changing these values would probably not change anything.


yeah, I think you're right Mark

Anyone had anymore thoughts on this.

It’s actually a weird topic - because so many of us are used to configuring aspects of our applications inside a framework, and the ORM configuration is done on the Application.cfc, which is far removed from that.

I’ve already stolen pieces of ColdBox within my Application.cfc, like this snippet in my onRequestStart:

if(isfwReinit()) { ormReload(); //load import data include "install/import.cfm"; }

But obviously I will want to do some other things in the actual setup of my Application.cfc request, i.e. have my dev settings of:

this.ormsettings = {
cfclocation = “model”
,dbcreate = “dropcreate”


this.ormsettings = {
cfclocation = “model”

I may just have to roll my own ‘environment’ checker within my Application.cfc.


Yes, this is a weird place for it. I wish somehow we had a way that cf provided for us to change the application.cfc settings somehow?

What about this thought Mark.

What if we could leverage a new interception point in the ApplicationStart() method of application.cfc

that would intercept and send in the “this” reference to it?

And then in the interceptor try to change the settings? Do you think this could work?

Ok guys, I have a proof of concept working. I was able to pass the application.cfc reference into the reloadchecks and the loading of coldbox, manipulate them in an interceptor and process.

So this is good news. However, here is the deal. The settings cannot be done via the normal environment control interceptor because basically it only fires once. As we all know, application.cfc get’s re-created in every request, so there is no persistence here.

Therefore, the solution would be to do a preProcess() interceptor that will manipulate the application.cfc settings before ANYTHING fires and make the call from the onRequest() method in Application.cfc

Here is what I also did. Registered a new custom interception point called: changeAppProperties

On my aplication.cfc onRequest() method after the reloadChecks() I did this:


That’s it!!

Then my interceptor receives the cfapplication as a “cfapp” key in the intercept data, I then change according to my environment setting the environment interceptor set and voila!!

switch( getSetting(“Environment”) ){


I should have responded to this sooner.

The question I have is - if you are editing the Application variables inside onRequest, are you able to actually influence how the ORM starts up, or does that have to be in the pseudo constructor?