English 中文(简体)
多形态协会的过滤器
原标题:Filter by polymorphic associations thinking sphinx

我有以下模式。

class Post < ActiveRecord::Base
  has_many :timeline_items, :as=>:subject

  define_index do
    ....?
  end
end

class TimelineItem < ActiveRecord::Base
  belongs_to :subject, :polymorphic=>true
  belongs_to :actor, :polymorphic=>:true
end

我想让属于特定行为者的所有职位都思考。

在<条码>中 我愿意这样做。

Post. where (temporal_items.actor_type = “User” and time_items.actor_id IN [1,2,3].includes(:timeline_items)

我的问题是,必须确定哪些指数,以及必须用什么方法得出同样的结果?

Update However I also need to filter the posts by different actor types like: Post.where( timeline_items.actor_type = "Group" AND timeline_items.actor_id IN [1,2,3]).includes(:timeline_items)

最佳回答

进行以下尝试:

define_index do
  # ...
  has timeline_items.actor.id, :as => :actor_ids
end

接着进行搜查:

Post.search  foo , :with => {:actor_ids => [1,2,3]}

如评论意见所详述,如果你需要对这些多形态协会的特定类别价值进行过滤,那么你就再需要为这一类别建立另一个联系。 这是因为Sphinx没有脊椎动物/高价值奶制品的概念,因此可以跟踪哪类婴儿。

一旦有了这一新协会,那么就为上述许多方面增添了一种归属感,或许就是这样:

has user_timeline_items.actor.id, :as => :user_actor_ids
问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签