Nov 3 2005

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.

Comments

SOSensible

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?
Joe Rinehart

Joe Rinehart wrote on 11/04/05 12:32 AM

Hey John - I'll reply in part:

Many-to-Many:

For now, you can represent this with three records, with one representing the relationship. Good example:

User -&gt; hasMany(UserRole)

Role -&gt; hasMany(UserRole)

UserRole -&gt; belongsTo(User)
UserRole -&gt; belongsTo(Role)

I'm on the fence about implementing the hasAndBelongsToMany() that doing this with only two would require. That's a lot of autowiring.

------

Naming conventions...this'll get doc'd soon:

1. Name tables in the singular. I didn't have time to implement the Rails inflector, and I really don't like plural table names. My apologies to anyone offended.

2. One primary key per table, and it is named &quot;#tablename#Id&quot;

3. Name your CFC file after the table: MyTable should be represented by MyTable.cfc. It can be in any package it wants, like my.warped.world.MyTable.

All of these conventions can be overridden, basically by the setTablename() and setPrimaryKey() methods on ActiveRecord.cfc.

-----------

Lists - they're coming, I need them too. May be a bit. For now, it's really not hard to implement yourself.

-----------

Trees - I'm not sure I want to touch this. If anyone wants to write some tree methods, feel free, I'd like to see it using adjacency lists, if possible.
Casey

Casey wrote on 09/29/08 3:53 AM

I'm on the fence about implementing the hasAndBelongsToMany() that doing this with only two would require. That's a lot of autowiring.
http://www.batteryfast.co.uk/acer/btp-amj1.htm acer btp-amj1 battery,
http://www.batteryfast.co.uk/acer/travelmate-3240.htm acer travelmate 3240 battery,
http://www.batteryfast.co.uk/acer/travelmate-3240.htm acer travelmate 3240 battery,
http://www.batteryfast.co.uk/acer/batecq60.htm acer batecq60 battery,
http://www.batteryfast.co.uk/acer/aspire-1800.htm acer aspire 1800 battery,
http://www.batteryfast.co.uk/apple/a1022.htm apple a1022 battery,
http://www.batteryfast.co.uk/apple/a1079.htm apple a1079 battery,
http://www.batteryfast.co.uk/apple/a1078.htm apple a1078 battery,
http://www.batteryfast.co.uk/apple/a1045.htm apple a1045 battery,

http://www.batteryfast.co.uk/apple/a1185-white.htm apple a1185 white battery,
http://www.batteryfast.co.uk/apple/a1185-black.htm apple a1185 black battery,
http://www.batteryfast.co.uk/asus/a42-a3.htm asus a42-a3 battery,
http://www.batteryfast.co.uk/asus/a3000.htm asus a3000 battery,
http://www.batteryfast.co.uk/asus/z9100.htm asus z9100 battery,
http://www.batteryfast.co.uk/asus/a3.htm asus a3 battery,
http://www.batteryfast.co.uk/asus/z91.htm asus z91 battery,
http://www.batteryfast.co.uk/asus/a32-a8.htm asus a32-a8 battery,
http://www.batteryfast.co.uk/asus/a8.htm asus a8 battery,

http://www.batteryfast.co.uk/asus/z99.htm asus z99 battery,
http://www.batteryfast.co.uk/asus/m3000.htm asus m3000 battery,
http://www.batteryfast.co.uk/asus/m3n.htm asus m3n battery,
http://www.batteryfast.co.uk/asus/m3000n.htm asus m3000n battery,
http://www.batteryfast.co.uk/asus/m3.htm asus m3 battery,
http://www.batteryfast.co.uk/asus/a42-m6.htm asus a42-m6 battery,
http://www.batteryfast.co.uk/asus/m6n.htm asus m6n battery,
http://www.batteryfast.co.uk/asus/m67.htm asus m67 battery,
http://www.batteryfast.co.uk/asus/m67n.htm asus m67n battery,
roulette online

roulette online wrote on 11/20/08 6:59 PM

roulette online
blackjack online

blackjack online wrote on 11/20/08 7:01 PM

blackjack online
blackjack software

blackjack software wrote on 11/20/08 7:03 PM

blackjack software
video poker online

video poker online wrote on 11/20/08 7:08 PM

vidoe poker online
poker review

poker review wrote on 11/20/08 7:15 PM

poker review

Write your comment



(it will not be displayed)