"but the key is then removed from a structure that is a property of an
internal, cached MG object"

Doh! I hope everyone has these stupid moments like me ;-)

>If all that seems like more effort than it's worth

Yeah - I will just stick with duplicate()

Thanks Ezra!


On Dec 13, 11:37 am, Ezra Parker <[email protected]> wrote:
> On Sun, Dec 13, 2009 at 11:00 AM, Jonathan Logue
>
> <[email protected]> wrote:
> > This is what I still don't get... I am deleting *after* I make a local
> > copy of the key's value...
>
> > <cfset var class = structFind(args,'class') />
> > <cfset structDelete(args,'class') />
>
> Right, which means that this works the first time the function
> executes, but the key is then removed from a structure that is a
> property of an internal, cached MG object. The event handler object is
> created when the application is initialized, not on every request, so
> once the argument is gone, any subsequent call to the method will fail
> due to the fact that it has been removed.
>
> The crucial thing to understand here is that the variable assignment
> of args = arguments.event.getAllArguments() does *not* create a copy
> of the arguments structure, but a reference to the structure stored
> within the framework's internal object. Using duplicate() circumvents
> this, as it creates a copy instead, and therefore the internal
> arguments structure is not modified.
>
> > Good point - I should probably use duplicate() anyway. The reason I
> > want to modify the arguments is that this method is a factory method
> > to return data from the model. I want to strip out "class" and
> > "returnVariable" before sending along.
>
> > <message name="getObjectsByClass">
> >        <argument name="class" value="Widget" />
> >        <argument name="WIDGET_TYPE" value="toy" />
> >        <argument name="ACTIVE" value="1" />
> >        <argument name="returnVariable" value="oWidgetRS" />
> > </message>
>
> Another way you could approach this would be to copy the arguments themselves:
>
> <cfset var args = structNew() />
> <cfset args.WIDGET_TYPE = arguments.event.getArgument("WIDGET_TYPE") />
> <cfset args.ACTIVE = arguments.event.getArgument("ACTIVE") />
>
> Or if you have varying properties, you could do this dynamically by
> looping over the arguments, excluding the class and returnVariable
> keys:
>
> <cfset var args = structNew() />
> <cfset var mgArgs = arguments.event.getAllArguments() />
> <cfset var key = "" />
>
> <cfloop collection="#mgArgs#" item="key">
>         <cfif key neq "class" and key neq "returnVariable">
>                 <cfset args[key] = mgArgs[key] />
>         </cfif>
> </cfloop>
>
> If all that seems like more effort than it's worth, then just change
> the line that sets the args variable like so and you should be good to
> go:
>
> <cfset var args = duplicate(arguments.event.getAllArguments()) />
>
> --
> Ezra Parker

-- 
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog

You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en

Reply via email to