Hi guys,
This is a hybrid ColdBox / ORM type question, but I think the answer is ORM related.
I have two entities.
Incident
IncidentEvent
events are a one-to-many relationship of Incident
{Incident Entity}
property name=“events” fieldtype=“one-to-many” cfc=“IncidentEvent” fkcolumn=“fk_incidentid” singularname=“event” cascade=“all-delete-orphan”;
{Incident Handler}
After creating an Incident I create an Incident Event and then return the incident status like so:
//create incident event
var incidentEvent = ormService.new(“IncidentEvent”);
// Populate Incident with the user’s input
BeanFactory.populateBean(target=incidentEvent,include='event_type,channel,incidentid,userid);
//save incident event
ORMService.save(incidentEvent);
//return the incident status
rc.results.setData(incidentService.getIncidentStatus(rc.incidentid,rc.userID));
…getIncidentStatus() looks like this:
struct function getIncidentStatus(required numeric IncidentID,numeric UserID) output=false{
var Incident = structNew();
if(isDefined(“arguments.UserID”)){
var qIncident = entityLoad(‘Incident’,{Incidentid=arguments.IncidentID,userid=arguments.UserID},true);
}else{
var qIncident = entityLoadByPK(‘Incident’,arguments.IncidentID);
}
if (!isNull(qIncident)){
Incident.id = qIncident.getIncidentID();
Incident.group = groupService.getGroup(qIncident.getGroupID());
Incident.dateCreated = qIncident.getDateCreated();
var incidentEvents = [];
if(arrayLen(qIncident.getEvents())){
for (i=1;i LTE ArrayLen(qIncident.getEvents());i=i+1) {
local.event = structNew();
local.event.type = qIncident.getEvents()[i].getEvent_Type();
local.event.user = qIncident.getEvents()[i].getUserID();
arrayAppend(incidentEvents,local.event);
}
}
Incident.events = incidentEvents;
}
return Incident;
}
CF is bombing when it tries to evaluate qIncident.getEvents() because the property does not exist or isn’t populated. Using CF Debugger I set a breakpoint after the qIncident call and looked at the variables of the object. Events was not listed.
After the failure if I make a subsequent call to getIncidentStatus(), the events property of Incident is Populated. So it appears that the ORMService.save(incidentEvent) call has not finished executing by the time i’m calling getIncidentStatus().
Any ideas what i’m doing wrong here?
Thanks.
Nolan