gpt4 book ai didi

ruby - 如何在 LIKE 与 Datamapper 之间建立 OR 条件?

转载 作者:数据小太阳 更新时间:2023-10-29 08:01:05 25 4
gpt4 key购买 nike

我有 3 个相关模型:

class Transaction
include DataMapper::Resource
property :id, Serial
property :volume, Float
property :deal_date, Date
belongs_to :buyer
belongs_to :seller
end

class Seller
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :transactions
end

class Buyer
include DataMapper::Resource
property :id, Serial
property :name, String, :length => 255, :index => true, :unique => true
has n, :transactions
end

我想在某些条件下查询交易:

x < volume < y
and
a < deal_date < b
and
( buyer.name like key_word OR seller.name like key_word )

如何使用 Datamapper 在两个 LIKE 之间创建 OR 条件?

最佳答案

简单查询Transaction,但查询路径为buyer.nameseller.name

Transaction.all('buyer.name.like' => keyword) | Transaction.all('seller.name.like' => keyword)

关于ruby - 如何在 LIKE 与 Datamapper 之间建立 OR 条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11888343/

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