README.md in mongoload-0.0.2 vs README.md in mongoload-0.0.3

- old
+ new

@@ -1,7 +1,7 @@ # Mongoload - +[![Gem Version](https://badge.fury.io/rb/mongoload.svg)](https://badge.fury.io/rb/mongoload) [![Build Status](https://travis-ci.org/karloku/mongoload.svg?branch=master)](https://travis-ci.org/karloku/mongoload) Mongoload is a gem to perform eager loading automatically for Mongoid, inspired by [Goldiloader](https://github.com/salsify/goldiloader). ## Usage @@ -16,16 +16,56 @@ Or install it yourself as: $ gem install mongoload -## TODO +## Options -* option to perform eager loading when calling following methods on an many/many_to_many relation: - + size - + first - + last -+ option to disable eager loading on specific relation +### :auto_include + +Mark if Mongoload should perform eager loading on the relation. +Pass ```:auto_include``` option to the definition, the value should be ```true```(by default) or ```false```. + +```ruby +class User + include Mongoid::Document + has_one :device, auto_include: false # Do not perform automatic eager loading on :device relation + has_many :posts + + field :username +end + +# Following call will not trigger automatic eager loading on device +User.all.each(&:device) +``` + +### :fully_load + +Mark if Mongoload should perform eager loading on the relation, when accessed by following methods: + + + #first + + #last + + #size + + #empty? + +Pass ```:fully_load``` option to the definition, the value should be ```true``` or ```false```(by default). + +```ruby +class Tag + include Mongoid::Document + has_and_belongs_to_many :posts, fully_load: true + + field :name +end + +# Following calls will trigger automatic eager loading on posts +Tag.all.each { |tag| tag.posts.first } +Tag.all.each { |tag| tag.posts.last } +Tag.all.each { |tag| tag.posts.size } +Tag.all.each { |tag| tag.posts.empty? } +``` + +PS: As for ```#second```, ```#third```, ```#fourth```, ```#fifth``` and ```#forty_two``` calls, mongoid will delegate them to the entries of a relation enumerable set, which makes them just same as a ```#to_a``` call. ## Copyright Copyright (c) 2016 Kaloku Sang