Access denied, Please sign in and make sure you have proper permission.
学习...union 似乎除了学的时候 一点都没用到了
但认为文中的例子不好,为什么不设计成 product 的 manager 也 tracking 这个 product?这样查询就退化 成 @user.tracking_products.ne(:manager_id, @user.id)
了?可以再用 scope 封装一下
@jasl 只是剛好想到這個例子作為範例,我也認同有些的程式碼其實是可從設計模型上解決的 :p
我遇到一个场景,
scope :belong_to_self, ->(user, team_ids) where(" company_id = ? and (user_id = ? or team_id in (?) ) ", user.company.id, user.id, team_ids)
因为 or 会影响索引,所以我就用 union all 把 or 给拆开了,但是 这样就不能写成上面那个公用的 scope 了,比较麻烦,不知道有还有什么解决办法不
#1 楼 @jasl
#2 楼 @bcmic