Ticket #61 (new enhancement)

Opened 2 years ago

Last modified 1 month ago

ErrrorCollection.merge() and getTranslatedErrors()

Reported by: mark.stanton@… Owned by: dhughes
Type: enhancement Priority: normal
Milestone: 1.0 Release Component: Reactor - General
Version: Severity: normal
Keywords: spam Cc:

Description

Merged errors are being treated as dictionary misses. For example:

<cfset TriangleRecord = reactor.createRecord("Triangle")>
<cfset PolygonRecord = TriangleRecord.getPolygon()>

<cfset TriangleRecord.setType("equilateral")>
<cfset PolygonRecord.setColour("red")>

<cfset TriangleRecord.validate()>

<cfif TriangleRecord.hasErrors()>

<cfset TriangleRecord._getErrorCollection().merge(PolygonRecord._getErrorCollection())>

</cfif>

<cfdump var="#TriangleRecord._getErrorCollection().getTranslatedErrors()#">

If I have an area column on my Polygon table that requires a value, I'd like the getTranslatedErrors() method look up the Polygon.area.notProvided error in my PolygonDictionary.xml and return the text I've specified there. However getTranslatedErrors() assumes that all the errors in the array will belong to the object on which it is being called, so it looks in the TriangleDictionary, doesn't find anything and just returns the text "Polygon.area.notProvided".

So what can we do about this?

I think the starting point would be to identify directionary misses. This could be done by checking if the value returned from getDictionary().getValue(arguments.error) is equal to arguments.error in ErrorCollection.getTranslatedError(). If its not a miss everything continues as is. If it is a miss then we need to work out if arguments.error matches an error message in a related dictionary.

There are two ways I can think of approaching this:

1) Have merge() not only append errors from one object's ErrorCollection into the other's, but also have it share or inject it's dictionary object into the target ErrorCollection. This would mean that each ErrorCollection would require an array of Dictionaries. The advantage of this is that the dictionary would be there, ready to go when getTranslatedError() error was called - getTranslatedError() would not have to worry about looking for or loading up other dictionaries.

2) Have getTranslatedError(), look at the error message (in this case Polygon.area.notProvided), use the first part to load up the correct dictionary through something like reactor.createDictionary(listFirst(arguments.error,'.')) and try and find a match there.

To me option 1) seems like a better approach, but I am unsure of exactly how it would be implemented. Maybe if the access for ErrorCollection.getDictionary() was changed to "package" merge() could call arguments.ErrorCollection.getDictionary()? Still not 100% happy with that idea...

Change History

Changed 2 years ago by rblatz

I believe that I have posted a fix for this in ticket 62.
http://trac.reactorframework.com/reactor/ticket/62

Changed 2 years ago by mark.stanton@…

Thanks mate - I have left a comment back on that ticket with my thoughts.

Changed 1 month ago by mark.drew@…

  • milestone set to 1.0 Release

Changed 1 month ago by TomChiverton

  • keywords spam added
Note: See TracTickets for help on using tickets.