[Coldbox 3.8.1] Problems (and solution) with Dynamic finders in BaseORMService

Hi, we are using a lot of functionality from BaseORMService, and most of it is very handy

Recently we discovered the Dynamic finders. Example is:


But in some cases these methods caused mapping errors, telling me my existing Domain component did not exist.
If I used a findWhere method from the same orm library things were OK, like

myObj = orm.findwhere(“Domain”,{ name = “mycompany.nl”});

For most other components things were fine, so we had to find differences. In this case we were using multiple datasources, and dynamic finders failed only on the non-default datasources.
I investigated the source code and saw the dynamic finders use HQL, wile the findwhere methods only use EntityLoad. In HQL you have to specify a datasource option if not using a default datasource, so this coud be solved in this way


Maybe documentation can be improved a little, so it is clear that dynamic finders are implemented in a different way compared to the findwhere methods? Specifying this datasource in every call is a workable solution (we do the same with HQL) but not very desirable,

Or another solution could be:
The findDynamically method already has an options struct for HQL options and an EntityName argument. From this entityname you could determine if a datasource was specified in the Entity definition. If so, it could be added to the options struct.

For now, we returned to the findwhere methods when using non standard datasources. Other syntax, other technique, but same results for exact matches.

Kind regards,


The reason we can’t use entity load is we allow for more complex finders like with this or this etc. Sorry for the confusion though.

No problem :slight_smile: We are quite happy with Coldbox, and there are plenty of easy workarounds. I just thought I would share this info with you. Just some mention of this in the docs would already save a lot of debugging. There are many more functions which don’t work as expected, at least if you don’t realize it is HQL based, such as all count, countwhere, dynamic counters and getAll,

deleteAll and deleteWhere are also HQL based but here the datasource is included by options.datasource = orm.getEntityDatasource(arguments.entityName);


Please add any issues to the project please so we can improve.https://ortussolutions.atlassian.net/secure/RapidBoard.jspa?rapidView=43&projectKey=CCM&view=detail

Ok, I created a login and posted this issue.