mongoid/mongoid — pull request #2544 by flexoid (2012-11-11 10:31:38+00:00)
Title: Added ability to specify fields in includes

Now it's possible to specify which fiels we want to eager load.
The result is exactly like usual `includes`, except that, regardless
of the fields specified, foreign key of the current relation always
loads. This is needed for the identity map.

Some examples:

# Actually eager loads people with 'name' and 'company_id' fields
Company.includes(people: {only: :name})

# The same, but with 'name', 'age' and 'company_id'
Company.includes(people: {only: [:name, :company_id]})

# Ignores :company_id in 'without', loads all except 'info'
Company.includes(people: {without: [:family_info, :company_id]})

# Of course, multiple relations can be specified
Company.includes(people: {without: :family_info}, equipment: {only: [:type, :model]})

I would appreciate additions and corrections.