Menu

The model layer represents the data structures and business logic, and is usually modeled by ColdFusion components. All ColdBox model objects are found under the modelfolder of the application root by convention. For security, place the models outside of the web root and use a ColdFusion Mapping to access them.

To learn more about ColdFusion Object Relational Mapping (ORM) and ColdBox model, visit these pages:

Please note that your data source must already exists in the ColdFusion Admin. Secondly, in the onRequestStartfunction in the same file, add it if it’s not already there (so that you can reload the application’s ORM):

if( structKeyExists(URL,"ORMReload") ){
ORMReload();
}

Create the Base Entity

We would like to strip out all the common properties of a model and place them inside this base entity. Then in each model that we create, we will inherit this base entity so that we keep the model as DRY as possible. To start off, create a new file called BaseEntity.cfc and save it into the modelfolder.

Here’s a simple component for the base entity (you can add, modify or remove properties and methods to suit your purposes, or create your own from scratch):