RE: Re: Re: [coldbox:21097] First Coldbox application

Thanks again for the help!

I ended up using mapDirectory(‘subdir.models’); to allow me to use subdirectories such as models/beans, models/DAOs, models/services.

Hopefully that’s best practice for organizing those objects. Would have thought ColdBox would default to recursive searching or do name matching based upon name suffix like FW/1.

Chris

> Hopefully that’s best practice for organizing those objects.

WireBox/ColdBox has no “best practices” on how or where you organize your models. By default, models are looked for in your models folder, but even the “models” convention folder is optional.

To get /models/foo.cfc use getModel( ‘foo’ )
To get /models/sub/foo.cfc use getModel( ‘sub.foo’ )

This is consistent with the way handlers or views work. You can create whatever sub directories you want and you just request that file with the full path relative to the root of the conventions folder.

> Would have thought ColdBox would default to recursive searching

It’s a common misconception that WireBox “searches” for CFCs by default. It does not. When you ask for a model, it looks in each of your scan locations for a path that matches what you asked for. It would not be in our best interest to make assumptions about your model names. Consider the following folders/CFC.

/models/admin/user.cfc
/models/site/user.cfc

In that example, there are two “user” CFCs floating around and for WireBox to just go recursively looking at names wouldn’t work when you did getMode( ‘user’ ). Which one do you want? Obviously, it is more correct that you would request getModel( ‘admin.user’ ) or getModel( ‘site.user’ ) which is the default behavior of WireBox.

The mapDirectory() trick is a shortcut you can take if you want to ignore your model’s packages AND you can guarantee that all the models in the directory have uniques names. WireBox isn’t going to force that assumption on you though.

> or do or do name matching based upon name suffix like FW/1

That’s an interesting behavior, but again everyone has their favorite way of naming their models and we’ve avoided trying to pick one over the other. I think we’ve given you plenty of tools to create mappings. There’s nothing stopping you from creating a module that recurses over a folder of your choice and creates mappings based on whatever naming convention you like the best. You can then put your model on ForgeBox and other people who like your approach can use it too :slight_smile:

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

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