我的模式是這樣的:寫作範圍,加入和秩序的示範
計劃has_many
措施 然後 措施has_many
目標 和目標表中有一個名爲列我的查詢是這樣的:
@programs2 = Program.includes([measures: :targets])
.some_scope
.where('organization_id = 1')
.limit(2)
我不知道在哪裏或如何編寫some_scope
部分查詢。 查詢以Program.includes
開頭,因此我認爲它應該在Program模型中進行定義,但是我的問題是measures: :targets
。我如何爲他們定義聯合。如果它只是一個表,我知道我可以這樣做:
scope :salary, :joins => :registry, :order => "money DESC"
我需要這一個了類似的事情,但是這兩個表像我上面所解釋的。我不知道該怎麼寫。
請停止[欺騙](http://stackoverflow.com/questions/15183785/scope-that-has-three-levels-deep-joins)你的問題。只要有人能夠回答,答案就會出現。 – mudasobwa 2013-03-03 09:35:41
@mudasobwa:對不起,我試圖從不同的觀點或方式來解答同一個問題,我可以解釋它。我認爲這一個是最明確和解釋版本的問題,我有tho :) – DarkNightFan 2013-03-03 09:42:50