Oh. I fooled myself. Thought the following would not work... but it does:
Product.unscoped do
my_photo.product
end
Notice that you have to call unscoped on the model with the default_scope
that should be bypassed.
Also, inheritance has to be respected. If you have class InsuranceProduct < Product
and class FinancialProduct < Product
and a default_scope
in Product
, all of the following two combinations will work:
InsuranceProduct.unscoped do
my_record.insurance_products
end
FinancialProduct.unscoped do
my_record.financial_products
end
Product.unscoped do
my_record.products
end
However, the following will not work although the scope is defined in Product
:
Product.unscoped do
my_record.financial_products
end
I guess that's another quirk of STI in Ruby / Rails.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…