README.md in goldiloader-0.0.10 vs README.md in goldiloader-0.0.11

- old
+ new

@@ -12,11 +12,11 @@ Wouldn't it be awesome if ActiveRecord didn't make you think about eager loading and it just did the "right" thing by default? With Goldiloader it can! Consider the following models: -``` +```ruby class Blog < ActiveRecord::Base has_many :posts end class Post < ActiveRecord::Base @@ -24,11 +24,11 @@ end ``` Here are some sample queries without the Goldiloader: -``` +```ruby > blogs = Blogs.limit(5).to_a # SELECT * FROM blogs LIMIT 5 > blogs.each { |blog| blog.posts.to_a } # SELECT * FROM posts WHERE blog_id = 1 @@ -38,11 +38,11 @@ # SELECT * FROM posts WHERE blog_id = 5 ``` Here are the same queries with the Goldiloader: -``` +```ruby > blogs = Blogs.limit(5).to_a # SELECT * FROM blogs LIMIT 5 > blogs.each { |blog| blog.posts.to_a } # SELECT * FROM posts WHERE blog_id IN (1,2,3,4,5) @@ -76,11 +76,11 @@ #### auto_include You can disable automatic eager loading on specific associations with the `auto_include` option: -``` +```ruby class Blog < ActiveRecord::Base has_many :posts, auto_include: false end ``` @@ -100,11 +100,11 @@ * `empty?` * `exists?` This can cause problems for certain usage patterns if we're no longer specifying eager loads: -``` +```ruby > blogs = Blogs.limit(5).to_a # SELECT * FROM blogs LIMIT 5 > blogs.each do |blog| if blog.posts.exists? @@ -116,11 +116,11 @@ # SELECT * FROM posts WHERE blog_id IN (1,2,3,4,5) ``` Notice the first call to `blog.posts.exists?` was executed via SQL because the `posts` association wasn't yet loaded. The `fully_load` option can be used to force ActiveRecord to fully load the association (and do any necessary automatic eager loading) when evaluating methods like `exists?`: -``` +```ruby class Blog < ActiveRecord::Base has_many :posts, fully_load: true end ``` @@ -130,25 +130,25 @@ ### has_one associations that rely on a SQL limit You should not try to auto eager load (or regular eager load) `has_one` associations that actually correspond to multiple records and rely on a SQL limit to only return one record. Consider the following example: -``` +```ruby class Blog < ActiveRecord::Base has_many :posts has_one :most_recent_post, -> { order(published_at: desc) }, class_name: 'Post' end ``` With standard Rails lazy loading the `most_recent_post` association is loaded with a query like this: -``` +```sql SELECT * FROM posts WHERE blog_id = 1 ORDER BY published_at DESC LIMIT 1 ``` With auto eager loading (or regular eager loading) the `most_recent_post` association is loaded with a query like this: -``` +```sql SELECT * FROM posts WHERE blog_id IN (1,2,3,4,5) ORDER BY published_at DESC ``` Notice the SQL limit can no longer be used which results in fetching all posts for each blog. This can cause severe performance problems if there are a large number of posts.