Alpha Blue wrote: > Hi Marnen, > > I see what you are saying and yes, that makes a lot of sense. I do use > each and often. I rarely use the (1..120) but could I perhaps do: > > datasize = Team.all.size > (1..datasize).each > > ?
If you were to do it that way, then you'd want to use Team.count. But you probably don't need the extra query... > > What I'm trying to accomplish and I only have to do this in a few > instances is that there will be times that I need to iterate over x > number of teams but I don't need to iterate over a returned query. Then why do you need to iterate over the 120 teams? You must have 120 of *something* if you are in a position where you need to do this. > > In otherwords, I'm creating data not pulling data. > > I can understand if I do something along the line of: > > team = Team.all > > team.each do |row| > .. > end > > But, I'm not working with the teams query, or any other query. I'm > working with actual data that I need to iterate over x number of teams > (by count) which happens to be 120 teams. So...what's the structure of that data? > However, you bring up a valid > point in that if another team enters FBS, I'd have to change the hard > count of the data iteration from 120 to 121. Yeah, magic numbers are generally bad. > This is why I believe > doing the .size would suffice. Except that it should be .count, so that it can use the DB's count(*) function. > > Unless, you think there is another way? > I think it's likely. The reason I asked about the structure of your data is that I strongly suspect that some part of it is an array of 120 elements. If not, then how are you using your loop index? > Thanks. Best, -- Marnen Laibow-Koser http://www.marnen.org [email protected] -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

