environment: rails 4.2, ruby 2.2.0
I was trying to add function something like find_each, but order by id descending.
I want to use it like this.
Person.where('age > 30').find_each_desc.each do |person|
end
I add method to ActiveRecord::Batches, it works great.
# file config/initializers/active_record.rb
module ActiveRecord
module Batches
def find_each_desc(options = {})
# do something
end
end
end
But if move to anthoer module, use include to add method, it's not working.
# file util/find_in_batches_with_order.rb
module Util
module FindInBatchesWithOrder
def find_each_desc(options = {})
# do something
end
end
end
# file config/initializers/active_record.rb
module ActiveRecord
module Batches
include Util::FindInBatchesWithOrder
end
end
# can get find_each_desc method
$ ActiveRecord::Batches.instance_methods
=> [:find_each, :find_in_batches, :find_each_desc]
ActiveRecord::Relation include ActiveRecord::Batches, so can find find_each_desc method in ActiveRecord::Relation instance methods, but not.
How should I do?