Deep association and Sphinx index with Thinking Sphinx?

我与影子孤独终老i 提交于 2020-01-04 16:00:50

问题


Currently I have the ff table:

Teams
id

Team_User
team_id, user_id

Users
user_id

Item
id
team_id

And the ff. model:

Team
has_and_belongs_to_many :users

User
has_and_belongs_to_many :teams

Item
belongs_to :audit_team, :class_name => "Team", :foreign_key => "team_id"

Why I am trying to archive is to get Sphinx to index all the user_id that associate with Item and I came up with this index definition:

  define_index do
    has audit_team.users(id), :as => :team_users
  end

I am not sure if this is correct or not. Also it's seam that Thinking Sphinx didn't build the config for this. As I rebuild, reindex and run the app, the ff. error shows up:

index ncpar_core: no such filter attribute 'team_users'

What could be the problem and how can I archive this?

Thank you very much


回答1:


You may need to run ts:rebuild after adding the attribute so Sphinx is aware of it. Also, perhaps it's a typo here instead of in your code, but id in the attribute definition should be a symbol:

has audit_team.users(:id), :as => :team_users


来源:https://stackoverflow.com/questions/10469864/deep-association-and-sphinx-index-with-thinking-sphinx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!