mongoid/mongoid — pull request #2243 by franc (2012-07-25 15:34:59+00:00)
Title: Allow array parameter for eager loading

I was getting the eager loading error in a new Rails app using RailsAdmin.

This is because their code sends includes as arrays. And Mongoid seems to create an array from a param list.

This patch allows mongoid to handle Foo.includes([:bar]) and Foo.includes(:bar)

# Before the patch:

1.9.3-p0 :002 > Account.includes([:user]).first
Mongoid::Errors::InvalidIncludes:
Problem:
Invalid includes directive: Account.includes(["user"])
Summary:
Eager loading in Mongoid only supports providing arguments to Account.includes that are the names of relations on the Account model, and only supports one level of eager loading. (ie, eager loading associations not on the Account but one step away via another relation is not allowed.
Resolution:
Ensure that each parameter passed to Account.includes is a valid name of a relation on the Account model. These are: "user".
from /Users/franc/.rvm/gems/ruby-1.9.3-p0@fisheagle/bundler/gems/mongoid-24ca957fb077/lib/mongoid/criteria.rb:365:in `block in includes'
from /Users/franc/.rvm/gems/ruby-1.9.3-p0@fisheagle/bundler/gems/mongoid-24ca957fb077/lib/mongoid/criteria.rb:363:in `each'
from /Users/franc/.rvm/gems/ruby-1.9.3-p0@fisheagle/bundler/gems/mongoid-24ca957fb077/lib/mongoid/criteria.rb:363:in `includes'
from /Users/franc/.rvm/gems/ruby-1.9.3-p0@fisheagle/bundler/gems/mongoid-24ca957fb077/lib/mongoid/finders.rb:10:in `includes'
from (irb):2
from /Users/franc/.rvm/gems/ruby-1.9.3-p0@fisheagle/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
from /Users/franc/.rvm/gems/ruby-1.9.3-p0@fisheagle/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
from /Users/franc/.rvm/gems/ruby-1.9.3-p0@fisheagle/gems/railties-3.2.6/lib/rails/commands.rb:41:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'

1.9.3-p0 :003 > Account.includes(:user).first
=> #

## After the patch:

1.9.3-p0 :004 > Account.includes([:user]).first
=> #

1.9.3-p0 :003 > Account.includes(:user).first
=> #

tests remain green and RailsAdmin works.