2013-07-18 43 views
1

記錄我將如何改寫這個要求,可獲取articlescurrent_user如果articlestemplateshas_and_belongs_to_many關係?我覺得我很接近,但我無法弄清楚。的Rails:獲得has_and_belongs_to_many協會

current_user.brand.articles.joins(:template).where(:templates => { :id => @template.id }) 

感謝您的幫助!

回答

1

不知道什麼brand協會代表和發佈您的模型將很長的路要走,以幫助弄清楚這一點,但這裏有一個猜測:

current_user.brand.articles.joins(:templates).where(:templates => { :id => @template.id }) 

你是在where子句中複數化templates但不是在加入。

+0

你猜對了。謝謝! –