テーブル内の列をソートするために meta_search を使用しています。テーブルの列の 1 つは、特定のモデルに関連付けられたレコードの数です。
基本的にはこれです:
class Shop < ActiveRecord::Base
has_many :inventory_records
def current_inventory_count
inventory_records.where(:current => true).count
end
end
class InventoryRecord < ActiveRecord::Base
belongs_to :shop
#has a "current" boolean on this which I want to filter by as well
end
Shop#index ビューには、各ショップの current_inventory_count を一覧表示するテーブルがあります。この数でお店を注文するために meta_search を使用する方法はありますか?
meta_search は ActiveRecord::Relation タイプを返すカスタム メソッドしか使用できないため、current_inventory_count メソッドを使用できません。
これを行うことについて考えることができる唯一の方法は、「仮想」列にカウントを含むカスタム SQL を実行し、この列で並べ替えを行うことです。それが可能かどうかはわかりません。
何か案は?
Rails 3.0.3 と最新の meta_search を使用しています。