This project is archived and is in readonly mode.
undefined method `zero?' for #<OrderedHash {}>
Reported by Chris Oliver | March 11th, 2011 @ 07:01 PM | in 3.0.6
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.
Comments and changes to this ticket
-
Andrew White March 11th, 2011 @ 07:49 PM
- 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?
-
Chris Oliver March 11th, 2011 @ 10:14 PM
Hey Andrew,
I got it working pretty easily through this patch: https://github.com/excid3/rails/commit/c360ae189cf5c6fa640c24634922...
-
Chris Oliver March 11th, 2011 @ 10:50 PM
Created a pull request as well: https://github.com/rails/rails/pull/218
-
Dan Pickett March 12th, 2011 @ 05:02 PM
- State changed from open to duplicate
I've added a note on #5829 referencing Chris' pull request. Closing this out as a duplicate.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>