gpt4 book ai didi

ruby - 是否可以使用 datamapper 进行 "where in"查询?

转载 作者:数据小太阳 更新时间:2023-10-29 07:23:58 24 4
gpt4 key购买 nike

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

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

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

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

最佳答案

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

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' ])

关于ruby - 是否可以使用 datamapper 进行 "where in"查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12897000/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com