Ticket #267 (closed defect: invalid)
Criteria for Generic Commit Does Behave correctly.
| Reported by: | dhughes | Owned by: | somebody |
|---|---|---|---|
| Priority: | highest | Milestone: | |
| Version: | Severity: | blocker | |
| Keywords: | Cc: |
Description
In the GenericOrmContoller?'s genericList method, there's a chunk of code that parses the criteria provided. This block of code allows you to provide a list of arguments. The arguments can be a simple string which represents the value of an event value with the same. Or, you can use foo=23 to set the criteria to the literal value 23. Lastly, you can use foo:bar to set the criteria to the value of the bar value in the event.
This last is very useful when you have an event argument named something like currentFooId, but you want to filter a list based on it's fooId. Thus, fooId:currentFooId.
The problem is that the ":" operator doesn't work correctly. Right now its code looks like this:
<cfif not arguments.event.valueExists(listFirst(field, ":"))>
<cfset arguments.event.setValue(listFirst(field, ":"), listLast(field, ":")) />
</cfif> <cfset criteria[listFirst(field, ":")] = arguments.event.getValue(listFirst(field, ":")) />
Using fooId:currentFooId as a an example, this seems to check to see if fooId exists in the event. If not, fooId is set into the event (which I might not want!) and it's set to the value "currentFooId". From there criteria.fooId is set to "currentFooId" (the value of fooId in the event). This seems like a very convoluted way to do the same thing as the = operator.
Instead, you should change this block to:
<cfset criteria[listFirst(field, ":")] = arguments.event.getValue(listLast(field, ":")) />
This sets critera.fooId = the value of curentFooId in the event.
