Read more

Retrieving the class an ActiveRecord scope is based on

Henning Koch
May 05, 2014Software engineer at makandra GmbH

Edge Rider Show archive.org snapshot gives your relations a method #origin_class that returns the class the relation is based on.
This is useful e.g. to perform unscoped record look-up.

Post.recent.origin_class
# => Post
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Note that #origin_class it roughly equivalent to the blockless form of #unscoped Show archive.org snapshot from Rails 3.2+, but it works consistently across all Rails versions. #unscoped does not exist for Rails 2 and is broken in Rails 3.0.

Posted by Henning Koch to makandra dev (2014-05-05 17:12)