Arf: Beware the Iterator
Posted by Joe Rinehart at 6:53 PM
8 comments - Categories:
Arf!
Some methods in Arf, like List() and Get[property]() where the [property] is set by a hasMany() or belongsToMany() declaration, return a QueryIterator object. This is a simple iterator that lets you loop over the query using QueryIterator.next(), getting each record in the iterator.
However, that's *not* the way you want to do things if all you want to show each object. If you want to simply display each object, or something along that line, use QueryIterator.GetQuery() to get the query and display it with <cfquery output="myQuery"> like you're used to.
Reasons:
* Using next() requires the iterator to ask the factory for an empty record, and then populates it from the query row. That takes a touch of time - it's not a big hit, but be aware that it's there.
* Using a query makes things like grouping, etc., work as it always has.
So, use queries when you don't need to actually work with the records :)
Note: this entry originally had some stats. They were wrong, so I pulled them. Turning off "report execution times" in the CFAdmin made the difference unnoticeable without a full-on load test.
SOSensible wrote on 11/03/05 11:13 PM
This seems like a familiar conversation. I am sure the query iterator is very trim! I love where you are going with this whole project and how well thought out it seems to be.A couple of questions...
1. For relations there are two basic types... one to many, and many to many. Where are you going with that?
2. Can you give us something with the naming conventions?
3. What about Hierrarchal Tables (or trees if some want a smaller word)
4. What about lists (as termed in RoR)
Could you share your thoughts on those subjects?