Introducing Unscoped Associations
Ruby on Rails is a great framework with a lot of interesting options. One of them is the ability to collect instances of a particular class using
default_scope. Very useful to collect “scoped” data by default, but pulling objects via associations is also affected.
It may be that you’ve ever needed to skip the
default_scope (for some strange reasons). This library allows you to do it easily.
More information, source and follow up here.
Add this line to your Gemfile:
From now on you are able to use
unscoped option in your association definitions. Basic usage example:
Tested on Rails 3.x series and Rails 4.0.0. Originally thought and built for Rails 3, Rails 4 supported.
NOTE: Rails 4 introduces some updates (and more planned for upcoming releases) related to this part. For example, in Rails 4, you are able to customize associations using a scope block, so you can skip
Anyway, you can use
unscoped option, if you prefer.
Feel free to fork, send ideas, bugs or any comment.