Monday, September 21, 2009

How to Override Rails default_scope in ActiveRecord

As noted on the activescaffold list, if you want to override Rails' default_scope you use send(:with_exclusive_scope):
Model.send(:with_exclusive_scope) { Model.find... }
For example, if you want to iterate through Cars you'd do:
(Car.send(:with_exclusive_scope) {Car.all}).each do |car|
  ...
end

No comments: