RE: [coldbox:17014] Re: ColdBox Bundle 3.5.3 - CriteriaBuilder Error

Did you guys ever get this issue sorted? Do we need to file a bug for something?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Hi Brad–

I don’t think it’s a bug (at least not in CB), and I confirmed the cause I mentioned in my last post on this thread. When a sorter has already been applied to the CriteriaBuilder, it will always blow up on the count() method since the produced SQL will be invalid.

While I didn’t look terribly hard, I wasn’t able to find a way to remove the sorter once it’s applied.

It might be worth considering documenting this. Where it really becomes an issue is when people (like myself) are creating functions that try to produce a structure of criteria query results and the total count of the criteria query itself.

For example, in my apps, I have a lot of data grids that do dynamic paging. So a typical process i have when populating the grid is to send through a request for 25 records with some filter criteria, sort order, etc. In my response, I need back not only the 25 (or less) records, but also a “count” of what the total recordset is that matches my criteria so that the grid can figure out its paging magic.

If you’re not paying attention, you can flip-flop the count() and list() methods, and get the errors that Don mentioned. Unfortunately, the error you get is not very helpful in debugging (when I ran into this I stumbled onto the answer by sheer frustration of moving around and deleting code until I figured it out).

I wouldn’t go as far as to say its a bug if this behavior exists elsewhere.

But I would highly recommend the Criteria Builder docs highlight this and let everyone know you shouldn’t call count() after list().