External Models and ORM - Can't find Entity

Hi guys,

I’ve setup my app to use the external model setting like so in order to maintain a common library of models, view, etc.

//Model Integration
models = {
objectCaching = true,
definitionFile = “config/modelMappings.cfm”,
externalLocation = “mysite.common.model”,
SetterInjection = false,
DICompleteUDF = “onDIComplete”,
StopRecursion = “”
};

Within the mysite.common.model folder I have a Location.cfc CF ORM entity as well as a LocationService.cfc service.

CB3 is registering the external model location successfully however when I access the LocationService through injection in my handler, CB is unable to find the Location entity. Error Messages: Mapping for component Location not found. ORM settings have been configured within Application.cfc and are working correctly. For this app config I’m keeping my ORMEventHandler in the implicit model path as I don’t want to mix it in with common library.

// ORM Setup
this.ormEnabled = true;
this.datasource = “mydb”;
this.ormSettings = {
dbcreate = “none”,
dialect = “MicrosoftSQLServer”,
logSQL = true,
eventhandling = true,
eventhandler = “model.ORMEventHandler”,
flushAtRequestEnd = false
};

Below is the code for my (simple) handler, entity and location service. The error only happens when the model and service is located in the external location, however if I move both to the implicit model location, everything works fine. Is there something I’m missing to get the entity to resolve when using the external location approach?

Many thanks.

Nolan

//Location Handler
//Location.cfc

component extends=“coldbox.system.EventHandler” output=“false”{

property name=“locationService” inject;

// OPTIONAL HANDLER PROPERTIES
this.prehandler_only = “”;
this.prehandler_except = “”;
this.posthandler_only = “”;
this.posthandler_except = “”;
// REST Allowed HTTP Methods Ex: this.allowedMethods = {delete=‘POST,DELETE’,index=‘GET’}
this.allowedMethods = {};

/**
IMPLICIT FUNCTIONS: Uncomment to use
function preHandler(event,action){
var rc = event.getCollection();
}
function postHandler(event,action){
var rc = event.getCollection();
}

function onError(event,faultAction,exception){
var rc = event.getCollection();
}
*/

function index(event){
var rc = event.getCollection();

rc.locations = locationService.list();
event.renderData(type=“JSON”,data=rc.locations);
}
}

//Location Entity
//Location.cfc

component persistent=“true” {

property name=“locationid” fieldtype=“id” generator=“increment”;
property name=“fk_userid”;
property name=“locationname”;
property name=“description”;
property name=“fk_locationaddressid”;
property name=“datecreated” ormtype=“timestamp” type=“timestamp”;
property name=“active”;

public string function getIDName() {

var id = StructFindValue( GetMetaData(This), “id”)[1].owner.name;
return id;
}

public any function getIDValue() {
return variables[getIDName()];
}

public void function setIDValue(any idvalue) {
variables[getIDName()] = arguments.idvalue;
}

public void function nullifyZeroID() {
if (getIDValue() eq 0){
variables[getIDName()] = JavaCast(“Null”, “”);
}
}

}

//Location Service
//LocationService.cfc

component output=“false” singleton{

LocationService function init() output=false{
return this;
}

any function list() output=“false”{
var users = entityLoad(“Location”);
return users;
}

any function getLocation(LocationID="") output=false{
if( len(arguments.LocationID) ){
var location = entityLoad(“Location”,arguments.LocationID,true);
if(NOT isNull(location) ){
return location;
}
}
return entityNew(“Location”);
}

void function save(Location location) output=false{
transaction {
arguments.location.nullifyZeroID();
entitySave(arguments.location);
}
}

void function remove(LocationID) output=false{
transaction{
// get location
var location = getLocation(arguments.LocationID);
if( NOT isNull(location.getLocationID()) ){
entityDelete(location);
}
}
}

array function getUserLocations(required FK_UserID) output=false{
return ormExecuteQuery(“from Location where FK_UserID = #arguments.FK_UserID#”);

//return entityLoad(“Location”,{UserID=arguments.UserID});
}

any function findAll(Active=false,boolean asQuery=false) output=false{
var results = entityLoad(“Location”,{Active=arguments.Active});

if( arguments.asQuery ){ return entityToQuery(results); }

return results;
}
}

Nolan,

The issue is with your ORM setup and not with Coldbox. You need to be sure to add your external location to the this.ormsettings cfclocation in your application.cfc.

For Example

this.ormSettings = {

dbcreate = “none”,

dialect = “MicrosoftSQLServer”,

logSQL = true,

eventhandling = true,

eventhandler = “model.ORMEventHandler”,

flushAtRequestEnd = false,

cfcLocation=["model”,”/someMappedModelFolder”,”/somelocation/model” ]

};

cfclocation :

Specifies the directory (or array of directories) that should be used by ColdFusion to search for persistent CFCs to generate the mapping. If cfclocation is set, ColdFusion looks at only the paths specified in it. If it is not set, ColdFusion looks at the application directory, its sub-directories, and its mapped directories to search for persistent CFCs.

Hope that helps,

Curt Gratz
Computer Know How

Hi Curt,

That did the trick! I had a feeling it was an ORM setting as opposed to CB. Thanks for clarifying.

Best,

Nolan