Permalink
Browse files

do not fetch associations if association id is nil

  • Loading branch information...
1 parent 25ac24d commit 624ec3d1f5cfd79bbc2293c98f9b4ddda99ae98d @flyerhzm committed Oct 26, 2010
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/mongoid/criterion/eager_loading.rb
View
6 lib/mongoid/criterion/eager_loading.rb
@@ -50,7 +50,7 @@ def setup_associations_with_ids(documents, reflection, one=true)
ids = []
documents.each do |document|
id_document_map[document.id] = document
- ids << document.id
+ ids << document.id if document.id
end
association_class = reflection.name.singularize.camelize.constantize
@@ -72,11 +72,11 @@ def setup_associations_with_foreign_keys(documents, reflection, one)
foreign_key_value = document.send(foreign_key_name)
if one
id_document_map[foreign_key_value] = document
- ids << foreign_key_value
+ ids << foreign_key_value if foreign_key_value
elsif foreign_key_value
foreign_key_value.each do |fkv|
id_document_map[fkv] = document
- ids << fkv
+ ids << fkv if fkv
end
end
end

0 comments on commit 624ec3d

Please sign in to comment.