Hello, bear with me here, just trying to figure so...
# cfml-general
s
Hello, bear with me here, just trying to figure something out. I have an ORM-system in CFML where I can get data-objects , that have other objects in them. So I can do rc.groupObj.getGroupsetting().getSpecificItem(). But now I want to loop over all the SpecificItems and get the data dynamically. So something like Evaluate("rc.groupObj.getGroupsetting().get#local.item#()"). But "Evaluate is Evil", so how can I get these values dynamically? I have a list of all the specific items and am looping over them, hence the Evaluate. Tried different forms of bracket-notations, but am just not getting it to run without errors 😐 . Any tips or ideas or suggestions would be helpful 🙂 .
s
I know on Lucee you can do:
dataObj.getGroupSetting()[ 'get#local.item()#' ]
the other option would be
invoke()
m
You typically use bracket notation to do that. Instead of
Evaluate("rc.groupObj.getGroupsetting().get#local.item#()")
it would be something like
rc.groupObj.getGroupsetting()["get#local.item#()"]
s
Thnx for the swift answers! Yeah, tried that bracket-type version and then get that component [groupsetting] does not have an accessible member with name [getspecificitem()]... Changing the brackets a bit back and forth or the quotes or the () does not help 😉.
@sknowlton that invoke-idea works! =>
#invoke(rc.groupObj.getGroupsetting(), "get#local.item#")#
gives me the value I am looking for! Great, thnx, never thought of working with invoke that way. Usually think of invoke as instantiating an object / CFC and getting the functions from it to use.
@miguel-f and @sknowlton this works though:
#rc.groupObj.getGroupsetting()["get#local.item#"]()#
Is that weird or do I just not get it why it works with such a notation?
Performancewise what would be faster? The first or the last using invoke you think? I am looping over 50 items and in my testing I do not see any difference in pageloading 😉
m
Glad you got it sorted Sebastiaan. I agree the notation looks weird. I'm no expert but I think the bracket notation will be faster. It's my understanding that it is a directive to evaluate the variable name only and then continue processing. No need to invoke anything. I am just guessing here. You prob won't see much difference with low iterations. Might need to test with more items to loop over.
🙏🏼 1
s
Bracket notation is faster according to 'our internal CFML lore' but I believe the basis of that is that
invoke()
used to, at least on ACF, clone the context, which could get expensive. I don't think it still does but also haven't used ACF since 2018. we very rarely have to use invoke() though, bracket notation does it for us when we need dynamic invocation. good call in having
evaluate()
be a red flag though
👍🏼 1