Both logger and arrayOfStructsSort are undefined when I dump the entity. I have successfully used entity injection in my 3.8. Can’t seem to find what I am missing. Any ideas where to look next?
orm = {
injection = {
// enable entity injection
enabled = true,
// a list of entity names to include in the injections
include = “”,
// a list of entity names to exclude from injection
exclude = “”
}
};
Note, entity injection needs to be enabled in two places. The Application.cfc, and in the Coldbox config struct that the cborm module uses. I do believe the default is true though if you don’t have the ORM struct in your ColdBox config.
eventhandler = “cborm.models.EventHandler” in this.ormSettings in application.cfc,
it works as expected.
However, I have my own models/ORMEventHandler.cfc where I extend “cborm.models.EventHandler”. When I do that, i do not get the injection. I use my own eventhandler to do things like update variables for all my tables like so:
public void function preUpdate( any entity, Struct oldData) {
var currentTime = now();
if (structKeyExists(arguments.entity,“setDateModified”))
arguments.entity.setDateModified(currentTime);
if (structKeyExists(arguments.entity,“setModifiedBy”) && len(getInstance(‘sessionStorage@cbstorages’).getVar(“user”).getID()))
arguments.entity.setModifiedBy(getInstance(‘sessionStorage@cbstorages’).getVar(“user”).getID());
}
If there is a better way to accomplish that, I’m happy to take a look.
Every method you override in the base class will need to call the super method. Otherwise, you are negating the base class entirely as the base method never gets called.
Thanks for the feedback. I think I missing something. The cfc you specific in this.ormsettings.eventhandler is supposed to be a global event handler. All the methods in my models.ORMEventHandler.cfc fire correctly without having to super them. What should I be using to trigger the entity injection? Something simple is probably escaping me…
Hooray. Working. In an earlier 3.8 app I was not using postLoad() or postNew() methods. I am on this 4.1 app. Added super. on those 2 methods and bingo.