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 professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
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)