Example of multiple datasources for ORM in 9.0.1
July 14, 2010
ColdFusion 9.0.1 brings multiple datasources support for ORM. Here is how to set it up.
In this example, we are going to use both the cfartgallery and cfbookclub datasources. In the Application.cfc we will make the cfartgallery the default datasource. Optionally we are going to set the dbcreate rules differently for the two datasources. (We could also do this for the schema, catalog, dialect and sqlscript settings.)
component
{
this.name="multi";
this.ormEnabled=true;
this.datasource="cfartgallery";
this.ormsettings = { dbcreate={ cfartgallery="update",
cfbookclub="none"} };
}
From cfartgallery we will use the Art table as an object. As cfartgallery is the default datasource, this is set up as usual:
component persistent="true"
{
property name="artID" fieldtype="id" ;
property name="artistID";
property name="artname";
property name="description";
property name="prize";
property name="largeimage";
property name="mediaID";
property name="issold";
property name="samColumn";
}
For any tables from the cfbookclub datasource there is an additional attribute "datasource" for the component:
component persistent="true" datasource="cfbookclub"
{
property name="bookID" fieldtype="id";
property name="authorID";
property name="title";
property name="bookdescription";
property name="isspotlight";
}
We can then get the data and dump it like so:
books = entityLoad("BOOKS", {}, {maxResults=2});
writeDump(books);
art = entityLoad("ART", {}, {maxResults=2});
writeDump(art);

Pretty straighforward and pretty cool stuff.
4 Comments
Some comments have been lost over the years due to moving hosts.
By: Jamie 11/15/2011 12:32 PM