2
class User < ActiveRecord::Base 
    has_many :followings, :as => :followable, :dependent => :destroy, :class_name => 'Follow' 
    has_many :follows, :as => :follower, :dependent => :destroy 

    define_index do 
    has follows.followable(:id), :as => :followable_id 
    has followings.follower(:id), :as => :follower_id 
    has follows.followable(:type), :as => :followable_type 
    has followings.follower(:type), :as => :follower_type 
    end 
end 
  1. 質問:私はタイプ(常に空の配列)で検索することはできません。バグ?フォロワーが「AAA」タイプのユーザーをすべて取得したいと考えています。Railsの+思考-スフィンクスのポリモーフィックな関連

    User.search ''、:=>と{:follower_type => 'AAA'}

  2. 質問:なぜ私は(インデックス定義)正しい結果を得るために、私の関連を逆しなければならないの: は、以下の(:id)、:as =>:followable_id の代わりにfollowable(:id)、:as:>:followable_id id = 1のユーザーのフォロワーのリストを取得します

    User.search:with => {:followable_id => 1}#id = 1のユーザのフォロワーのリスト

Thx!

答えて

2

最初の質問に関して - 文字列フィルタはスフィンクスでは機能しません。これは将来(スフィンクスが新機能をサポートした後、スフィンクス1.10ベータ版では)変化するはずですが、いつ起こるのかはわかりません(私はすぐに言いたいのですが、何も約束できません)。

ご利用いただけますが、文字列の配列を扱っているので、複雑さが増しています。

2番目の質問は、データベースがどのように見えるか(頭が混乱する名前ですが、今は焦点がない)に頭を下げるのに苦労しています。

+0

@pat Thxあなたのansware用!データベースについては、このプラグインを参照してください:https://github.com/xpepermint/acts_as_followable。モデルはそこからコピーされます(2番目の質問用)。 – xpepermint

+0

@patまた、最初の質問には "CRC32(follow.flowable_type)"があります。:as:>:followable_type、:type =>:integer "index definition right?働いていない。 – xpepermint

+1

':type =>:multi'を試してください - あなたは整数の配列を扱っています。フィルタは ':with = = {{followable_type => 'AAA'.to_crc32}'でなければなりません。 – pat

関連する問題