Sure Andrew, the scenario is like this.
There are 2 scenarios that I would appreciate your help on:
Scenario 1 - When I need all Properties:
I am creating an API which does CRUD for the place I am working at.
For List calls the API Call will contain 2 additional parameters if needed for Search and for Sort, like this
`
searchParams:[
{
“property”:“user_role”,
“method”:“eq”,
“value”:“R01”
},
{
“property”:“meal_role”,
“method”:“eq”,
“value”:“SU”
}
]
sortParams:[
{
“property”:“user_role”,
“method”:“desc”
},
{
“property”:“user_name”,
“method”:“asc”
}
]
`
What I need is to search if the property is indeed part of the ORM Object and then I will do search or sort using the requested method (naturally there is authentication and checking if the method is valid).
The code for Sorting would be like this:
`
if (isDefined(“rc.sortParams”)) {
for (sortParam in DeserializeJSON(rc.sortParams)) {
if (ListFindNoCase(propertyList, sortParam.property)) {
var getMe = listGetAt(propertyList, ListFindNoCase(propertyList, sortParam.property));
c.order(getMe, sortParam.method);
} else {
returnMe.returnMessage = returnMe.returnMessage & ‘Error Search: #sortParam.property# not found in #rc.reqFunction#|’;
}
}
};
`
The problem I have is when I try to use getPropertyNames to get the propertyList
`
var propertyList= TableService.getPropertyNames(“ORMObject”);
`
then properties that are Keys will not be returned. So I will not be able to validate and therefor not be able to do search or Sort for Key Properties.
Scenario 2 - Calling Function of an ORM Entity:
I was looking at Dan Vega’s Blog for a Solution and inside he suggested putting Functions inside the Object, like this:
`
component accessors="true" {
property userid;
property firstname;
property lastname;
/**
* @hint this method will return an array of key/pair values for
* each property in our component dynamically.
*/
public array function getPropertyValues(){
// the properties of our component
var properties = getMetaData(this).properties;
// the return array
var propertyValues = [];
for(i=1; i <= arrayLen(properties); i++){
var property = {};
property.key = properties[i].name;
property.value = getPropertyValue(property.key);
arrayAppend(propertyValues,property);
}
return propertyValues;
}
private any function getPropertyValue(String key){
var method = this["get#key#"];
return method();
}
}
`
Which got me wondering, if it is possible to call an object of an ORM Entity. For example:
`
var TableService = new VirtualEntityService(entityName=user);
writeDump(TableService.getPropertyValues());
`
But this was not working. Am I missing something here?
Thanks
Julian