我正在使用gem searchkick,并且我想在searchkick的搜索方法中进行如下查询:Product.where("products.created_at < products.distribution_ended_at")

这是我的模特产品

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


这是我的产品负责人

    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_ended_at可能等于nil。尝试:

search_conditions = {
  created_at: { lt: params[:distribution_ended_at] }
}

关于mysql - Searchkick用DateTime查询的语法是什么,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42806027/

10-11 09:02