using the BASE ORM correctly

Last question of the night. If I go back to the Base ORM service
method I get the following error....

"Element CAMPAIGNS is undefined in a CFML structure referenced as part
of an expression. "

let me show you want I am doing "wrong" as I now have to inject each
time and I think I am getting confused.

First at the top of my handler I tell it what to inject

property name="campaignService" inject="entityService:campaign";

now from my understanding campaignService.cfc has the entity
campaign.cfc ready and waiting, (correct?) I take it entityService is
CB base handler.

so now in my handler I try the following line of code...

rc.campaigns = campaignService.getAllCampaigns();

this finds a function in my campaignService.cfc called
getAllCampaigns.

campaignService.cfc looks like this...

/**
* A service layer that handles all campaign operations
*/
component output="false" singleton{

  campaignService function init() output=false{
    return this;
  }

  any function getAllCampaigns() output=false{
    var results = ORMService.getAll("campaign");
    return results;
  }

now I get the error...

"Element CAMPAIGNS is undefined in a CFML structure referenced as part
of an expression. "

so could you explain this to me better. sorry for the dumb questions,
but its the way I learn :slight_smile:

looking at it more I see that I don't need to inject the
entityService, so I tried below...

property name="campaignService" inject="campaign";

I still get the same error tho when trying to use the following in my
handler

rc.campaigns = campaignService.getAllCampaigns();

error

"Element CAMPAIGNS is undefined in a CFML structure referenced as part
of an expression. "

this is my function in the cfc

  any function getAllCampaigns() output=false{
                var results = ORMService.getAll("campaign");
                return results;
        }

any reason why the function is not returning anything?

Thanks

getAllCampaigns() is returning a null value, which is why rc.campaigns doesn’t exist.

Have you tried just dumping out a simple EntityLoad(“Campaign”), to make sure that the ORM stuff is working? Also does your Campaign entity have any relationships set up that mave be causing an issue?

Can you also say which version of ColdBox you’re running as this might have been fixed in SVN, but not in the build you’re running.

yes it works with the virtual service but using the base ORM no I just
get an empty array

current code

Handler
component extends="coldbox.system.EventHandler" output="false"{
  property name="campaignService" inject="entityService";
  /* index handler dashboard */
  function index(event){
    var rc = event.getCollection();//get scope
    var campaign = entityLoad("campaign");
    writeDump(campaign);
    abort;
    rc.campaigns = campaignService.getAllCampaigns();
    event.setView("dashboard/index");//load view
  }

campaignService.cfc

component extends="BaseORMService"{
  public campaignService function init(){
      super.init(useQueryCaching=true);
      return this;
  }
  any function getAllCampaigns() output=false{
      var campaign = "";
    campaign = ORMService.getAll("campaign");
    return campaign;
  }

strange think is anything I get from the campaignService always
returns that error event it I hard code a value and just try to return
that!

so for example say i do the following in my service...

  any function getAllCampaigns() output=false{
      var campaign = "1";
    return campaign;
  }

I get

Element CAMPAIGNS is undefined in a CFML structure referenced as part
of an expression.

The error occurred in C:\inetpub\wwwroot\cms.yourbrandreality.co.uk
\coldbox\system\includes\panels\CollectionPanel.cfm: line 21
Called from C:\inetpub\wwwroot\cms.yourbrandreality.co.uk\coldbox
\system\includes\Debug.cfm: line 253
Called from C:\inetpub\wwwroot\cms.yourbrandreality.co.uk\coldbox
\system\web\services\DebuggerService.cfc: line 201
Called from C:\inetpub\wwwroot\cms.yourbrandreality.co.uk\coldbox
\system\Coldbox.cfc: line 321
Called from C:\inetpub\wwwroot\cms.yourbrandreality.co.uk
\Application.cfc: line 59

19 : </tr>
20 : <cfloop collection="#thisCollection#" item="vars">
21 : <cfset varVal = thisCollection[vars]>
22 : <tr>
23 : <td align="right" width="15%"
class="fw_debugTablesTitles"><strong>#lcase(vars)#:</strong></td>

Your injection is wrong!!

you have
property name=“campaignService” inject=“entityService”;

That means that it will create a VIRTUAL file for you and inject it as campaignService. This virtual file is a vanilla base orm service. However, you have created your OWN service called campaignService that templates out the base orm service. So you need to inject THAT object and not the virtual objects.

property name=“campaignService” inject=“model:campaignService”;

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Hi Luis,

I see now thanks for explaining it. works perfectly.