检查带有filtercriteria的entityLoad是否返回了结果

Jas*_*son 1 coldfusion coldfusion-9

我这样调用entityLoad:

currentSubmission =  entityload("EventSubmission", { eventID = variables.eventID, profileID = variables.profileID, true }
Run Code Online (Sandbox Code Playgroud)

如何检查entityLoad是否已返回记录?如果filtercriteria上存在匹配项,则返回Object.如果没有匹配项,则不返回任何内容,并且变量currentSubmission不存在.

我发现的问题是,如果我使用:

一个.isObject(currentSubmission),在没有返回任何内容时给出错误,因为currentSubmission不存在.

湾 isDefined(currentSubmission),在返回某些内容时给出错误,因为您无法在对象上执行isDefined.

问题是,我应该使用什么方法来确定entityLoad是否返回了结果?

这是我试图整理的完整方法.基本上,我想基于某些过滤条件加载实体并返回它,如果没有匹配的实体,则返回一个新的Empty实体.

public function getByEventProfile(){
    currentSubmission =  entityload("EventSubmission", { eventID = variables.eventID, profileID = variables.profileID }, true);
    if (!isObject(currentSubmission))
        currentSubmission = entityNew("EventSubmission");
    return currentSubmission;
}
Run Code Online (Sandbox Code Playgroud)

Hen*_*nry 6

isNull() 是你正在寻找的功能.

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSe9cbe5cf462523a0-3c4c0bb81223f1daffb-8000.html

更新:虽然isDefined()structKeyExists()可能工作,isNull()事实上的功能,用于检查是否entityLoad()找到任何东西.事实上,CF9中引入它仅仅是为了做到这一点.