1
我想覆蓋現有的範圍以向其添加額外的條件。我已經展示了使用alias_method來做到這一點的嘗試。不幸的是,這種方法不適用於範圍,我得到一個未定義的方法錯誤。我如何用範圍做到這一點?在導軌3中覆蓋範圍
module Delayed
module Backend
module ActiveRecord
class Job < ::ActiveRecord::Base
belongs_to :queue
scope :in_unlocked_queue, lambda {
joins(:queue) & Queue.unlocked
}
alias_method :orig_ready_to_run, :ready_to_run
scope :ready_to_run, lambda {|worker_name, max_run_time|
orig_ready_to_run(worker_name, max_run_time).in_unlocked_queue
}
end
end
end
end
如果我還記得,你可以使用的方法,而不是在AR3範圍......但我不完全當然。 – Reactormonk 2010-10-24 18:30:36