3种型号:
Class Product
include Mongoid::Document
has_many :orders, dependent: :destroy, :autosave => true
#search
searchable do
text :title, :description, :boost => 2.0
time :created_at
end
end
Class Order
include Mongoid::Document
belongs_to :product
has_one :dispute, dependent: :destroy, :autosave => true
end
Class Dispute
include Mongoid::Document
belongs_to :order
field :buyer_has_requested_refund, :type => Boolean, :default => "false"
end
我需要在内部products_controller.rb
采取index
行动,从高到低排序所有与订单有争议的产品buyer_has_requested_refund = true
就像是:
def index
@search = Product.solr_search do |s|
s.fulltext params[:search]
s.keywords params[:search]
s.order_by :disputes_where_buyer_has_requested_refund, :desc
end
@products = @search.results
respond_to do |format|
format.html # index.html.erb
end
end
谢谢!