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
ありがとうございました!