README.md in goldiloader-0.0.5 vs README.md in goldiloader-0.0.6
- old
+ new
@@ -66,11 +66,11 @@
$ gem install goldiloader
## Usage
-By default all associations will be automatically eager loaded when they are first accessed so hopefully most use cases should require no additional configuration.
+By default all associations will be automatically eager loaded when they are first accessed so hopefully most use cases should require no additional configuration. Note you're still free to explicitly eager load associations via `eager_load`, `includes`, or `preload`.
### Association Options
Goldiloader supports a few options on ActiveRecord associations to customize its behavior.
@@ -122,12 +122,58 @@
class Blog < ActiveRecord::Base
has_many :posts, fully_load: true
end
```
+## Limitations
+
+Goldiloader leverages the ActiveRecord eager loader so it shares some of the same limitations.
+
+### 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:
+
+```
+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:
+
+```
+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:
+
+```
+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.
+
+### Other Limitations
+
+Associations with any of the following options cannot be eager loaded:
+
+* `limit`
+* `offset`
+* `finder_sql`
+* `group` (due to a Rails bug)
+* `from` (due to a Rails bug)
+* `unscope` (due to a Rails bug)
+* `joins` (due to a Rails bug)
+* `uniq` (only Rails 3.2 - due to a Rails bug)
+
+Goldiloader detects associations with any of these options and disables automatic eager loading on them.
+
## Status
-This gem is tested with Rails 3.2, 4.0, and 4.1 using MRI 1.9.3, 2.0.0, 2.1.0 and JRuby in 1.9 mode. [Salsify](http://salsify.com) is not yet using this gem in production so proceed with caution. Let us know if you find any issues or have any other feedback.
+This gem is tested with Rails 3.2, 4.0, and 4.1 using MRI 1.9.3, 2.0.0, 2.1.0 and JRuby in 1.9 mode.
+
+Let us know if you find any issues or have any other feedback.
## Change log
See the [change log](https://github.com/salsify/goldiloader/blob/master/CHANGELOG.md).