this.datasource versus this.ormsettings.datasource

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.

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;