Permalink
Browse files

support mongoid 2.0.0.rc.6

  • Loading branch information...
1 parent 7bcc211 commit 6231061ccb55af194ff3b500457b14ab8874541d @flyerhzm committed Jan 20, 2011
Showing with 7 additions and 6 deletions.
  1. +7 −6 lib/mongoid-eager-loading/mongoid/criterion/eager_loading.rb
@@ -35,13 +35,14 @@ def association_reflection(document_class, eager_loading)
end
def setup_associations(documents, reflection)
- if reflection.association == Mongoid::Associations::ReferencesOne
+ case reflection.macro
+ when :references_one
setup_associations_with_ids(documents, reflection, true)
- elsif reflection.association == Mongoid::Associations::ReferencesMany
+ when :references_many
setup_associations_with_ids(documents, reflection, false)
- elsif reflection.association == Mongoid::Associations::ReferencesManyAsArray
+ when :references_and_referenced_in_many
setup_associations_with_foreign_keys(documents, reflection, false)
- elsif reflection.association == Mongoid::Associations::ReferencedIn
+ when :referenced_in
setup_associations_with_foreign_keys(documents, reflection, true)
end
end
@@ -53,7 +54,7 @@ def setup_associations_with_ids(documents, reflection, one=true)
ids << document.id if document.id
end
- association_class = reflection.name.singularize.camelize.constantize
+ association_class = reflection.class_name.constantize
ignore_includes
eager_associations = association_class.where(reflection.foreign_key.to_sym.in => ids.uniq).to_a
eager_associations.each do |eager_association|
@@ -83,7 +84,7 @@ def setup_associations_with_foreign_keys(documents, reflection, one)
end
end
- association_class = reflection.name.singularize.camelize.constantize
+ association_class = reflection.class_name.constantize
ignore_includes
eager_associations = association_class.find(ids.uniq).to_a
eager_associations.each do |eager_association|

0 comments on commit 6231061

Please sign in to comment.