![](/img/trans.png)
[英]Fatch records on the bases of has_and_belongs_to_many association -Rails
[英]Rails: get records for has_and_belongs_to_many association
如果articles
和templates
具有has_and_belongs_to_many
關系,我將如何重寫此請求以將articles
提供給current_user
? 我覺得我已經接近了,但我不太清楚。
current_user.brand.articles.joins(:template).where(:templates => { :id => @template.id })
謝謝你的幫助!
不確定brand
協會代表什么並發布您的模型將有助於找出這一點很長,但這是一個猜測:
current_user.brand.articles.joins(:templates).where(:templates => { :id => @template.id })
您在where子句中使用了復數templates
,但在聯接中沒有。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.