【问题标题】:is it possible to do a "where in" query with datamapper?是否可以使用数据映射器进行“在哪里”查询?
【发布时间】:2012-10-15 13:48:04
【问题描述】:

我想从datamapper获取与指定ID匹配的对象列表。

我知道我可以使用多个“”条件,但 id 的列表可能有数百个。

有没有datamapper命令相当于下面的sql?

select * from table where id in (1,2,3,4,5)

【问题讨论】:

    标签: ruby ruby-datamapper


    【解决方案1】:

    你可以!它看起来像这样:

    users = User.all(:id => [1,2,3])
    

    编辑:你可以在github page for dm-core看到这个:

      # If the value of a pair is an Array, we do an IN-clause for you.
      Person.all(:name.like => 'S%', :id => [ 1, 2, 3, 4, 5 ])
    
      # Does a NOT IN () clause for you.
      Person.all(:name.not => [ 'bob', 'rick', 'steve' ])
    

    【讨论】:

    • DM 猴子补丁符号? egads。
    猜你喜欢
    • 2017-06-29
    • 2015-01-25
    • 2021-05-15
    • 2018-02-04
    • 2019-03-05
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    相关资源
    最近更新 更多