[英]In Rails5, how do I return the union of two scopes or combine them into one?
[英]How do I combine scopes in rails?
如果我有2個產品類范圍,我可以這樣做。
Product.best.sale #retrieves best and sale
出於某種原因,我有兩個獨立的范圍,如下所示。
a = Product.best
b = Product.sale
a.b #ERROR
我試過ab,它給出了一個錯誤。
如何組合a和b來獲取Product.best.sale?
謝謝。
山姆
分配b
,您應該將范圍鏈接到a
而不是新的Product
調用:
a = Product.best
b = a.sale
a.b
# => Retrieves best and sale
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.