Given a model with default_scope to filter all outdated entries:
# == Schema Information
#
# id :integer(4) not null, primary key
# user_id :integer(4) not null, primary key
# end_date :datetime
class Ticket < ActiveRecord::Base
belongs_to :user
default_scope :conditions => "tickets.end_date > NOW()"
end
Now I want to get any ticket. In this case with_exclusive_scope is the way to go, but is this method protected? Only this works:
Ticket.send(:with_exclusive_scope) { find(:all) }
Kind of a hack, isn't? So what's the right way to use? Especially when dealing with associations, it's getting even worse (given a user has many tickets):
Ticket.send(:with_exclusive_scope) { user.tickets.find(:all) }
That's so ugly!!! - can't be the rails-way!?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…