簡體   English   中英

Rails:獲取has_and_belongs_to_many關聯的記錄

[英]Rails: get records for has_and_belongs_to_many association

如果articlestemplates具有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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM