Specify currently grabbed records within Model class method

Viewed 233

I have a class method where I want to modify the records that are currently grabbed by an ActiveRecord::Relation object. But I don't know how to refer to the current scope in a class method. self does not do it.

Example:

class User < ActiveRecord::Base
  ...

  def self.modify_those_records
    #thought implicitly #to_a would be called on currently grabbed records but doesn't work
    temp_users_to_a = to_a
    ...
  end
end

I would use it like this:

User.some_scope.modify_those_records

So User.some_scope would return to me an ActiveRecord::Relation that contains a bunch of User records. I then want to modify those records within that class method and then return them.

Problem is: I don't know how to explicitly refer to "that group of records" within a class method.

3 Answers
Related