this.datasource versus this.ormsettings.datasource

This post is more than 2 years old.

This probably falls into the obvious category, but if you are using ORM and have code that sets the datasource in the ormsettings, it will not apply to basic cfquery calls.

//Application.cfc this.ormEnabled=true; this.ormSettings.datasource="monkeypower";

//foo.cfc var q = new com.adobe.coldfusion.query(); q.setSQL("select mediatype from media where media like :search"); var results = q.execute().getResult();

//ERROR!

But - if you set this.datasource, it applies to both your cfquery calls as well as your ORM calls.

//Application.cfc this.datasource="monkeypower"; this.ormEnabled=true;

//foo.cfc var q = new com.adobe.coldfusion.query(); q.setSQL("select mediatype from media where media like :search"); var results = q.execute().getResult();

//HAPPY MONKEYS!!

I suppose you could use different values for each, but I'd bet most people are using one DSN and probably still use a few "basic" queries even when making use of ORM.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Mike Hodgson posted on 4/22/2011 at 1:36 AM

Good tip! Got caught by this when I first started using ORM, now I usually put this at the top of my Application.cfc:

this.datasource = 'MyDatasource';
this.ormEnabled = true;
this.ormSettings.datasource = this.datasource;