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
question: Je ne peux pas la recherche par type (toujours tableau vide). Un bug? Je voudrais obtenir tous les utilisateurs où les adeptes sont de type «AAA».Rails + Pensée-Sphinx association polymorphique
User.search '',: avec => {: follower_type => 'AAA'}
question: Pourquoi dois-je inverser mon association pour obtenir le bon résultat (définition d'index): suit .followable (: id),: as =>: followable_id au lieu de followings.followable (: id),: as =>: followable_id Je voudrais avoir la liste des abonnés pour un utilisateur avec id = 1
User.search: with => {: followable_id => 1} # Liste des abonnés pour un utilisateur avec id = 1
Thx!
@pat Thx pour votre logiciel espion! Pour la base de données s'il vous plaît voir ce plugin: https://github.com/xpepermint/acts_as_followable. Le modèle est copié à partir de là (pour la deuxième question). – xpepermint
@pat La première question devrait aussi avoir "has" CRC32 (follows.followable_type) ',: as =>: type_executable,: type =>: entier "définition de l'index à droite? Ne fonctionne pas – xpepermint
Essayez ': type =>: multi' - vous avez affaire à un tableau d'entiers. Et le filtre devrait être ': with => {: followable_type => 'AAA'.to_crc32}'. – pat