isORM(item)
Last updated May 30, 2010
Version: 1 | Requires: ColdFusion 9 | Library: DatabaseLib
Description:
There is no built in way to check this with a single function at this time. So I created a way to check if the element was either and ORM entity or collection of entities.
Return Values:
Returns a boolean.
Example:
myStruct = structNew();
myQuery = queryNew();
selector = { id = 12 };
myEntity = EntityLoad('entityClass',selector,true);
</cfscript>
<cfoutput>
myStruct : #is_orm(myStruct)#<br>
myQuery : #is_orm(myQuery)#<br>
myEntity: #is_orm(myEntity)#<br>
</cfoutput>
- - - - -
This will give the following result.
- - - - -
myStruct : false
myQuery : false
myEntity : true
- - - - -
We are using this logic inside our ReturnData.cfc inside COOP. It enables us to treat the entity as a generic data source and integrate lists, array of structures, queries and entities as data sources without having to manually set an attribute on custom tags and object methods. It's nice to have some intuition in our code.
Parameters:
| Name | Description | Required |
|---|---|---|
| item | Value to check. | Yes |
Full UDF Source:
<cfscript>
/**
* Validates if item is orm entity or collection.
*
* @param item Value to check. (Required)
* @return Returns a boolean.
* @author John Farrar (johnfarrar@sosensible.com)
* @version 1, May 30, 2010
*/
function isORM(item) {
var metaItem = {};
try {
if(isArray(arguments.item) && arrayLen(arguments.item)){
metaItem = getMetadata(arguments.item[1]);
} else {
metaItem = getMetadata(arguments.item);
}
if(structKeyExists(metaItem,'persistent') && metaItem.persistent){
return true;
} else {
return false;
}
} catch(any e) {
return false;
}
}
</cfscript>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
4 day(s) ago
Will Belden added
longTime
9 day(s) ago
James Sleeman added
quickSort
19 day(s) ago
Ben Forta added
GetHostAddress
22 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)