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
問題:I不能通過類型(總是空數組)搜索。一個錯誤?我希望所有用戶的追隨者都是'AAA'類型。導軌+思維-斯芬克斯多態關聯
User.search',:用=> {:follower_type => 'AAA'}
的問題:爲什麼我要逆我聯想到得到正確的結果(索引定義): 如下。:可追蹤(:id),:as =>:followable_id 而不是 followingings.followable(:id),:as =>:followable_id 我想獲得id = 1的用戶的追隨者列表。
User.search:with => {:followable_id => 1}#id爲1的用戶的關注者列表
Thx!
@pat Thx for your answare!對於數據庫請看這個插件:https://github.com/xpepermint/acts_as_followable。模型從那裏複製(對於第二個問題)。 – xpepermint 2010-11-27 11:04:55