Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

undefined method `zero?' for #<OrderedHash {}>

#6564

I'm working on a small application for class, and get the following bug Rails 3.0.4 and 3.0.5:

@tours = Tour.where(["date = ?", @date]) \
             .order("date ASC, time ASC") \
             .joins("LEFT JOIN visitors ON tours.id = visitors.tour_id") \
             .group("tours.id") \
             .select("tours.*, COALESCE(SUM(visitors.total_party), 0) as current")

# puts @tours # This will fix the issue
@tours.empty?

undefined method `zero?' for #2, 26=>1}> happens when I call @tours.empty?. If I do anything like print out @tours or access it in any other way, empty? exists then and it will work fine.

I imagine it's a simple fix in ActiveRecord, but I don't know where to look in order to patch it myself.

Reported by Chris Oliver · March 11th, 2011 @ 07:01 PM

State: duplicate
Milestone: 3.0.6
Assigned to: Andrew White Andrew White
Importance: Low

Activity

  1. Andrew White
    Andrew White
    • State changed from new to open
    • Milestone set to 3.0.6
    • Assigned user set to Andrew White
    • Importance changed from to Low

    A good place to start would be the empty? method declaration in ActiveRecord::Relation - it does a count.zero? which because you're grouping returns an ordered hash rather than a simple count.

    Do you want to try to make a patch?

    March 11th, 2011 @ 07:49 PM

  2. Chris Oliver
    Chris Oliver

    Thanks Andrew! I will try to make a patch today.

    March 11th, 2011 @ 08:00 PM

  3. Chris Oliver
  4. Chris Oliver
  5. Andrew White
  6. Dan Pickett
    Dan Pickett
    • State changed from open to duplicate

    I've added a note on #5829 ActiveRecord::Relation#empty? fails for grouped relations, as OrderedHash is ... referencing Chris' pull request. Closing this out as a duplicate.

    March 12th, 2011 @ 05:02 PM