Skip to content

Commit

Permalink
Adding group bang
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Sep 20, 2009
1 parent ef98dbb commit 008c997
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/mongoid/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ def find_all(selector = nil)
# Find all Documents given the supplied criteria, grouped by the fields
# provided.
def group_by(fields, selector)
collection.group(fields, selector, { :group => [] }, GROUP_BY_REDUCE).collect do |grouping|
grouping["group"] = grouping["group"].collect { |attributes| new(attributes) }
grouping
collection.group(fields, selector, { :group => [] }, GROUP_BY_REDUCE).collect do |docs|
group!(docs)
end
end

Expand Down Expand Up @@ -157,6 +156,11 @@ def add_association(type, class_name, name)
end
end

# Takes the supplied raw grouping of documents and alters it to a
# grouping of actual document objects.
def group!(docs)
docs["group"] = docs["group"].collect { |attrs| new(attrs) }; docs
end
end

# Read from the attributes hash.
Expand Down

0 comments on commit 008c997

Please sign in to comment.