Answer the question
In order to leave comments, you need to log in
What is the correct way to add a has_and_belongs_to_many relationship to a sphinx index?
Hello everyone)) In the project, sphinx is used as a search. There are entities
class Catalog::Product < ActiveRecord::Base
has_and_belongs_to_many :writers, class_name: 'Catalog::Author', join_table: "catalog_authors_products"
end
class Catalog::Author < ActiveRecord::Base
has_and_belongs_to_many :products, class_name: 'Catalog::Product', join_table: 'catalog_authors_products'
end
ThinkingSphinx::Index.define 'catalog/product', with: :active_record do
indexes :title, facet: true
indexes :id
indexes :sku, as: :sku_field
indexes writers(:first_name), as: :writer_first_name
has created_at
has available
has price
has sku
end
indexes writers(:first_name), as: :writer_first_name
and when trying to do a rake ts:rebuild an error pops up ERROR: index 'catalog_product_core': sql_range_query: Unknown column 'catalog_authors.product_id' in 'on clause' (DSN=mysql://root:***@localhost:3306/byblos_dev) . Googled, everyone writes the habtm connection in this formatindexes writers(:first_name), as: :writer_first_name
or so , but the error is the same.
In the development.sphinx.conf fileindexes writers.first_name, as: :writer_first_name
LEFT OUTER JOIN catalog_authors ON catalog_authors.product_id = catalog_products.id
apparently the sphinx does not correctly determine the connection!? Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question