我正在使用gem searchkick我想做这样的查询:Product.where("products.created_at < products.distribution_ended_at")
在searchkick的搜索方法中
这是我的模型产品
class Product < ActiveRecord::Base
searchkick word_start: [:name]
def search_data
{
name: name,
content: content,
amount: amount,
created_at: created_at,
distribution_ended_at: distribution_ended_at
}
end
end
这是我的产品 Controller
class ProductsController < ApplicationController
def index
@products = Product.all
search_conditions = {
created_at: {lt: distribution_ended_at}
}
sort_conditions =[]
aggregations = {}
@product = Product.new
@products = Product.search("*", aggs: aggregations, where: search_conditions,
page: params[:page], per_page: 20, match: :word_start, order: sort_conditions)
end
end
但问题是,找不到 distribution_ended_at
有人知道如何在 Searchkick 的搜索条件中编写此查询吗?
谢谢
最佳答案
distribution_ending_at
可能等于 nil
。尝试:
search_conditions = {
created_at: { lt: params[:distribution_ended_at] }
}
关于mysql - Searchkick 使用 DateTime 查询的语法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42806027/