【问题标题】:How to get the inverse of where ids => collection of ids in Rails如何获得 where is => Rails 中的 id 集合的倒数
【发布时间】:2013-09-06 01:02:34
【问题描述】:

我正在尝试返回与此相反的语句:

scope :subscribed, lambda {|user| where(:venue_id => user.flagged_venues)}

flagged_venues 返回一个 id 数组,所以当我运行该语句时,我会得到所有标记的场所。我真正想要的是完全相反的:除了标记的场馆之外的所有场馆。

我尝试使用!= 而不是=>,但返回了所有场地。

当它更改为where("venue_id <> ?", user.flagged_venues) 时,我收到此错误:PG::DatatypeMismatch: ERROR: argument of WHERE must be type boolean, not type record LINE 1: SELECT "events".* FROM "events" WHERE (venue_id 2,4)

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    你想要不在flagged_venues列表中的id,所以我猜你应该替换

    where(:venue_id => user.flagged_venues)
    

    where("venue_id not in (?)", user.flagged_venues)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-12
      • 1970-01-01
      • 2021-12-06
      • 2013-08-21
      • 2015-12-01
      • 2012-09-21
      • 1970-01-01
      相关资源
      最近更新 更多