简体   繁体   中英

upgrading Thinking Sphinx - deep association

Ran into something in upgrading from TS 2.x to TS 3.1.1

I have a through association: bar has_many category_groups through bar_category_groups

In my index for bar, I have this, and it works fine:

has bar_category_groups(:category_group_id), :as => :cat_groups

I also have model "foo", which belongs to a bar. In my index for foo, I had this before, and it worked fine in TS 2.x

has bar.bar_category_groups(:category_group_id), :as => :cat_groups

In TS 3, I get "ThinkingSphinx::MissingColumnError: column bar_category_groups does not exist"

I do also have joins for bar and bar.bar_category_groups at the top of my index.

It seems as though we lost the ability to have a through association hanging off of a belongs to association (a "deep" association if you will).

You shouldn't need to have the column as a method argument - instead, just chain it as a method:

has bar.bar_category_groups.category_group_id, :as => :cat_groups

The argument syntax is something that was added to old versions of TS to work around reserved methods in Ruby 1.8 - but now that BasicObject is a thing, it's no longer necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM