Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix NilClass error when parent objects are empty

  • Loading branch information...
commit f489341e509b9e2b3a926a425b7a0551fd3b7e8e 1 parent 1f223bc
@flyerhzm authored
View
3  lib/mongoid-eager-loading/mongoid/criterion/eager_loading.rb
@@ -18,12 +18,13 @@ def includes(*options)
end
def preload(documents)
+ return if documents.blank?
document_class = documents.first.class
@eager_loadings.each do |eager_loading|
setup_associations(documents, association_reflection(document_class, eager_loading))
end
end
-
+
private
def ignore_includes
@eager_loadings = nil
View
7 spec/mongoid-eager-loading/mongoid/criteria_spec.rb
@@ -23,5 +23,12 @@
criteria.collect(&:title).should == ["Sir", "Madam"]
criteria.collect(&:game).should == [@person1.game, @person2.game]
end
+
+ it "empty parent objects with include" do
+ Game.destroy_all
+ Person.destroy_all
+ criteria = Person.includes(:game)
+ criteria.collect(&:game).should == []
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.