Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Criteria#merge sets documents collection

  • Loading branch information...
commit d3467d534ccc7e821e520bb8185c6f92a49adc17 1 parent 4f5fec5
@durran durran authored
Showing with 20 additions and 3 deletions.
  1. +4 −3 lib/mongoid/criteria.rb
  2. +16 −0 spec/unit/mongoid/criteria_spec.rb
View
7 lib/mongoid/criteria.rb
@@ -17,6 +17,8 @@ module Mongoid #:nodoc:
class Criteria
include Enumerable
+ attr_accessor :documents
+
attr_reader :klass, :options, :selector
# Returns true if the supplied +Enumerable+ or +Criteria+ is equal to the results
@@ -234,7 +236,7 @@ def id(object_id)
# type: One of :all, :first:, or :last
# klass: The class to execute on.
def initialize(klass)
- @selector, @options, @klass = {}, {}, klass
+ @selector, @options, @klass, @documents = {}, {}, klass, []
if klass.hereditary
@selector = { :_type => { "$in" => klass._types } }
@hereditary = true
@@ -318,10 +320,9 @@ def max(field)
#
# <tt>criteria.merge({ :conditions => { :title => "Sir" } })</tt>
def merge(other)
- # TODO: If an embedded documents array exists on the criteria merge it in
- # as well.
@selector.update(other.selector)
@options.update(other.options)
+ @documents = other.documents
end
# Used for chaining +Criteria+ scopes together in the for of class methods
View
16 spec/unit/mongoid/criteria_spec.rb
@@ -564,6 +564,22 @@
@criteria.selector.should == @selector
@criteria.options.should == @options
end
+
+ end
+
+ context "when the other has a document collection" do
+
+ before do
+ @documents = [ stub ]
+ @other = Mongoid::Criteria.new(Person)
+ @other.documents = @documents
+ end
+
+ it "merges the documents collection in" do
+ @criteria.merge(@other)
+ @criteria.documents.should == @documents
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.