我想弄清楚是否有一種方法可以重用AR調用中的範圍。這是我的例子Rails 3 - 訪問範圍鏈以重用
@current_account.items.report_by_month(month, year)
裏面的report_my_month範圍,我想重用@current_account
def self.report_by_month(month, year)
values = Values.where(:current_account => USE SCOPE FROM SELF)
scope = scoped{}
scope = scope.where(:values => values)
end
這只是示例代碼,找出如何做到這一點,因爲查詢要複雜得多因爲這是一個報告。謝謝!
打電話請發表您的型號代碼.. – 2012-03-22 03:06:45
模型是巨大的,我試圖訪問current_account在self.report_by_month。不知道爲什麼模型的其他部分甚至會相關。試圖看看我能否得到一個scope.current_account.subdomain或類似的東西 – bokor 2012-03-22 22:52:20
我們不需要整個模型代碼,但發佈模型之間的關係將幫助您更快地得到答案。 – 2012-03-22 23:14:36