I’m just getting started with ColdBox on Lucee and was attempting to test out the ORM functionalities but I’ve hit a snag.
Initially, I was playing with an existing app and had some issues, to try to isolate my issue I started with a brand new project.
From memory here’s what I’ve done based on http://coldbox.ortusbooks.com/content/index.html
I created my app in
c:\inetpub\www\myapp\ with install coldbox
coldbox create app name=MyApp skeleton=AdvancedScript
coldbox create controller name=hello actions=index,echo
The hello world ran fine in the built-in CF engine so I moved on and configured it with a Lucee service and an IIS site on my locahost at local.myapp.
I tried running the hello world action again and it ran fine so IIS and Lucee are configured properly.
Moved on to try and enable the ORM -
I added the following to my application.cfc
// ORM Settings
this.ormEnabled = true;
this.datasource = "contacts";
this.ormSettings = {
cfclocation = "models",
dbcreate = "update",
logSQL = true,
flushAtRequestEnd = false,
autoManageSession = false,
eventHandling = true,
eventHandler = "cborm.models.EventHandler"
};
and added the following to coldbox.cfc configure()
orm = { injection = { enabled=true } };
I created the contacts datasource within Lucee server admin (MS SQL)
Then I ran
coldbox create orm-entity entityName=contacts primaryKey=contactID properties=firstName,lastName,email --activeEntity --open
This created a Contacts.cfc file under model as expected.
Afterward I ran
coldbox create handler name=contacts actions=index,editor,delete,save
This created the handler and I was able to load the index action fine.
I then modified the handler's index function to:
function index(event,rc,prc){
prc.contacts = entityNew("Contact").list(sortOrder="lastName",asQuery=false);
event.setView( "contacts/index" );
}
I restarted the Lucee services to make sure everything would reinit properly and tried loading it which gives me the following error:
Messages: No entity (persitent component) with name [Contact] found, available entities are []
From what I was able to gather, I think this might mean that ColdBox is not finding my contact model or that there is a syntax error within it preventing it from getting init'd, but I'm not sure where to check.
My orm.log under C:\inetpub\www\myapp\WEB-INF\lucee\logs is empty
The full CFC code is:
/**
* A cool contacts entity
*/
component persistent="true" table="contacts" extends="cborm.models.ActiveEntity"{
// Primary Key
property name="contactID" fieldtype="id" column="contactID" generator="native" setter="false";
// Properties
property name="firstName" ormtype="string";
property name="lastName" ormtype="string";
property name="email" ormtype="string";
// Validation
this.constraints = {
// Example: age = { required=true, min="18", type="numeric" }
};
// Constructor
function init(){
super.init( useQueryCaching="false" );
return this;
}
}