[ColdBox 4.0.0] Submodule can access parent module orm?

In an coldbox 4.0 app I have a module with a submodule.

Can I access from submodule to a parent module orm?

I’ve tried with:

`

function configure(){
// Binder Mappings
binder.map(“SecurityRuleService”).to(“modules.myparentmodulespath.models.SecurityRuleService”);
}

`

But I got this errror: Message: invalid component definition, can’t find component [area51.models.SecurityRuleService]

I’m not sure this question has anything to do with ORM, and I’m also not entirely sure what you mean by “access”.

The code sample appears that you’re trying to create a WireBox mapping for a CFC in your parent module. I would recommend against this. Module should be little black boxes that encapsulate functionality. If a module has a CFC, it needs to create the mapping itself. Of course, in ColdBox 4 your mapping is redundant since CFCs in the models folder are all mapped by default so there’s no need to map them again anywhere unless you wish to override something.

Now, if the sub module wants to get an instance of the CFC defined in its parent, it should simply ask WireBox for it based on its mapping name.
getInstance( ‘cfcName@moduleName’ )

And as to whether or not the CFC is an ORM entity, that doesn’t really make any difference other than the fact that you’ll want to use an ORM service to access it.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

One more thought that came to me right as I hit send-- you may have your modules backwards. When module A has module B inside of it-- think of that relationship as “module A depends on, or requires module B”, not the other way around.

So, module B should really only be nested inside of module A if it specifically provides some service or functionality that module A needs to run.
If module B is just another part of your app that happens to use module A, it can just live next to it as a sibling in the app’s module directory.

So imagine each module should, in theory, be accessing other modules next to it at the same level, or the first level of modules inside of it. If a module is trying to depend on its parent, or its child’s child’s child, then you’re sort of asking for trouble by complicating the dependency graph.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Thanks Brad, I really appreciate your help. However there are some points that aren’t clear to me.

I have this folder structure:

  • modules
  • admin

+models

  • modules
  • adminInstaller

What i’m trying to accomplish is to create a submodule that should fill database with some securityrules, admin users and some roles. My idea is to create a simple installer that could be removed after baasic record creation.

To obtain this I have adminInstaller submodule that has only a model that performs some databse savings. In adminInstaller moduleconfig I have:

`

function configure(){ // Binder Mappings binder.map(“SecurityRuleService@admin”).to(“admin.models.security.SecurityRuleService”); }

/**

  • Fired when the module is registered and activated.
    */
    function onLoad(){
    var installService = wirebox.getInstance(“InstallerService@area51installer”);
    installService.execute();
    }

`

In the installerService I have this injection:

`

// DI
property name=“securityRuleService” inject=“SecurityRuleService@admin”;

`

If I remove this line: binder.map(“SecurityRuleService@admin”).to(“admin.models.security.SecurityRuleService”); I got error:

`
Railo 4.2.1.008 Error (Builder.DSLDependencyNotFoundException) Message: The DSL Definition {REF={null}, REQUIRED={true}, ARGNAME={}, DSL={id:SecurityRuleService@admin}, JAVACAST={null}, NAME={securityRuleService}, TYPE={any}, VALUE={null}, SCOPE={variables}} did not produce any resulting dependency Detail: The target requesting the dependency is: ‘InstallerService@adminInstaller’

`

So this is probably because when adminInstaller is loaded the admin module models aren’t yet loaded?

Yes, it’s possible they’re just loading in the wrong order. Use this.dependencies in your moduleconfig.cfc to specify any modules that need to be loaded first.

https://github.com/bdw429s/cbox-validation/blob/master/modules/cbvalidation/ModuleConfig.cfc#L28

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Many thanks Brad!!!

This solve my problem. Let me say that the coldbox 4.0 is great and with commandbox the development is really fast. Keep on good working!!!