Transfer: get{OneToMany|ManyToMany}Iterator() Never-Ending Loop
Posted on July 11, 2008 at 7:11 AM in ColdFusion, Transfer
When using Transfer in your application, you'll often have a One-to-Many (o2m) or a Many-to-Many (m2m) relationship in your Transfer config file. If you review the generated methods docs, you will see that you can grab an iterator with which to loop over the object collection. When you do, don't be a dweeb like me and create a never-ending loop.
Look carefully at the following two snippets of code.
Sample 1:
- <cfscript>
- var i = 0;
- var temp = "";
- var iterator = getEmailIterator();
- while ( iterator.hasNext() ) {
- temp = iterator.next();
- i = i+1;
- }
- return i;
- </cfscript>
Sample 2:
- <cfscript>
- var i = 0;
- var temp = "";
- while ( getEmailIterator().hasNext() ) {
- temp = getEmailIterator().next();
- i = i+1;
- }
- return i;
- </cfscript>
See the difference in them? It's rather subtle, but it'll bring your processor to its knees if you choose the wrong one. Which one is right? Which one is wrong?
This post is probably of very little benefit to anyone else. Honestly, I decided to write it while it was fresh on my mind so that (a) hopefully I will remember it better [since I wrote it down], and (b) so I can refer back to it the next time I forget again and cripple my server with the wrong version... again. (Yeah, I did. You can quit laughing now.)
"Well, which damn one is it, Quack?"
Oh, yeah. Sorry, I forgot about that. If you chose Sample 1 as the correct one, you owe yourself a pat on the back. If you chose Sample 2 as the correct one, welcome to my world, my friend!
Latest Articles
- No recent entries.
Categories
- ColdBox (21) [RSS]
- ColdFusion (92) [RSS]
- Fusebox (3) [RSS]
- General (22) [RSS]
- jQuery (15) [RSS]
- Kalendar (1) [RSS]
- Linux (1) [RSS]
- Mura CMS (1) [RSS]
- Railo (1) [RSS]
- Rants (5) [RSS]
- Transfer (8) [RSS]
- Uni-Form Tag Library (36) [RSS]
Quick Links
Blogs I Read
Calendar
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
« Feb | ||||||
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Subscribe
Enter a valid email address.
On 5/29/09 at 3:46 PM, pedro said:
Thanks for the post. Insteresting!
Pedro.