ORM Virtual Service / Models in Modules

I am working on creating an internal module for my application - using the rest-hmvc sample application for inspiration - but have hit a snag…

The application started off by using the coldbox advanced skeleton application.
It uses ORM and virtual services.

I am currently working on creating an incident reporting capabilities to add to the original application system - as a module, that has 2 parts,
The reporting of an incident and the investigation of an incident.
So (at least at the moment) my directory path looks like:

app_root
   |- handlers
   |- models
   |- views
   |- modules
   |- modules_app
          |- Incidents
                  |- ModuleConfig.cfc
                  |- config
                  |- modules_app
                        |- Reports
                              |- ModuleConfig.cfc
                              |- config
                              |- handlers
                              |- views
                              |- models
                                      |- Report.cfc
                        |- Investigations
                              |- ModuleConfig.cfc
                              |- config
                              |- handlers
                              |- views
                              |- models
                                      |- Investigation.cfc

In it’s first iteration - where I had app_root/module_app/Incidents/module_app/{Reports/Investigations} just displaying some static text - the routing etc all works as expected -showing me the stand-in view files for the correct path/module.

However - I am stuck, now that I want to add change the statis views into forms and use a service and model with the new module’s forms.

The (beginning) contents of app_root/module_app/Incidents/module_app/Reports/handlers/Report.cfc is:

component extends = "coldbox.system.EventHandler" {

	property name = "ORMService" inject = entityService:Reports";
	property name = "StaffDetailService" inject = "entityService:StaffDetail";
...
}

However I get an error:

No entity (persistent component) with name [Reports] found

It then lists out the persistent entities that are found in app_root/models

Attempting to get the Reports portion working at:
app_root/module_app/Incidents/module_app/Reports

I have read the HMVC/Modules documentation

I have tried all the following (restarting commandbox between iterations) - but have not yet managed to get the virtual service / new persistent CFCs to work.
property name = "ORMService" inject = entityService:Reports@Incidents";
and
property name = "ORMService" inject = entityService:Reports@Incidents:Reports";
and
property name = "ORMService" inject = entityService:Reports@Incidents/Reports";
and
property name = "ORMService" inject = entityService:Reports@Incidents.Reports";

(More a question than a statement)
I am not sure if the hierarchy (extends) portion of the Report handler is correct (I just copied what is in the “base” portion of the application.

As an extra - I have also tried placing the models directory into:
app_root/module_app/Incidents/models/Reports.cfc
(Which matches the documentation - at least how I read it to be)

Can anyone see what I am doing wrong?
As always - Thanks!

Is it just a typo in your directory structure layout that you are trying load

/module_app/Incidents/module_app/Reports/models/Report.cfc

which is singular, Report.cfc with a plural entityService:Reports ?

My other thought is that with your module layout, the Report model belongs to the Reports Module so if it is not a typo, than I believe it should be:

property name = "ORMService" inject = "entityService:Report@Reports";

Not sure, but thats my first thought! Maybe it will help.

The singular/plural-ness of the command here - uses the name of the model which in my case - are all singular. And follows the “convention” from other coldbox skeleton apps that I have used as training aids.

For my guidance here I uses the hmvc-rest skeleton application.
it has modules_app/api/v1 as a structure.

Using this skeleton app - is how I got the first iteration working when it was just static content.

And this “module” - seemed like a candidate for the same namaing convention.
You can appreciate that at some stage there might be a api/v2 directory…

And similarly - I am trying to create an “Incidents” module (overall) - but with a “Reports” section and a separate “Investigations” - so I followed the idea of api/v1 api/v2 for my Incidents/Reports and 'Incidents/Investigations portions.

I THINK the issue is with the ColdBox Virtual Service.
In that it assumes that models live in app-root/models ONLY.
I haven’t looked into the source code - but that is my assumption…

In the hmvc-rest skeleton app the models ARE in the app-root/models and not in app-root/modules_app/api/v1 folder… so that (unconvincingly) supports my current guess…

Just to clarify, I was trying to make two points based on your directory path map as you showed it.

  1. It looks like the entity name as outlined in your directory is report not reports based on /app_root/module_app/Incidents/module_app/Reports/models/Report.cfc
  2. The structure you are using (based you your directory path map) means that ColdBox will load Incidents , Reports, and Investigations as three separate modules and the Investigations does not have any models, meaning that the report model belongs to the reports module and the model Investigation belongs to the Investigations module. This means that regardless of the report vs reports question, Reports@Incidents and Report@Incidents would be invalid since the Incidents module has no models.

I am familiar with the hmvc-rest skeleton. How is the API module separation of api/v1 and api/v2 integrated with the directory path map above, specifically the Incidents , Reports, and Investigations modules? Usually you would just create new models or significantly changed model in each api version module, otherwise you can load models from previous versions where they are needed and aren’t changed. The idea is that you can build v2 off of v1, etc.

Also, keep in mind that if you create a module inside each of the v1 or v2 with the same name, ColdBox would only load the first module with that name and ignore the rest and you can’t rely on which one it would load.

The hmvc-rest module organization creates a module named API and then modules under that named v1, v2, etc. @lmajano has a good example of the hvmc-rest with multiple versions here:

Another good repo to look over is the ContentBox source code:

ContentBox uses ORM and loads models from other modules so it might give you some pointers.

I hope this helps. Maybe we can get @lmajano, the creator of ColdBox to weigh in. He’s good at pointing out where I am off track. :grinning:

1 Like

"oh… I get it… NOW!:

Despite the hierarchical nature (of the physical paths) - the module IS its own discreet thing…
Which is so obvious… but only when someone points it out.

I have now got things working - in the sense that I have moved on from this issue!
Thanks very much!

1 Like