Всем привет)) В проекте в качестве поиска используется sphinx. Есть сущности
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
и при попытке сделать rake ts:rebuild выскакивает ошибка ERROR: index 'catalog_product_core': sql_range_query: Unknown column 'catalog_authors.product_id' in 'on clause' (DSN=mysql://root:***@localhost:3306/byblos_dev). Гуглил, все записывают связь habtm в таком формате
indexes writers(:first_name), as: :writer_first_name
или так
indexes writers.first_name, as: :writer_first_name
, но ошибка одна и таже.
В файле development.sphinx.conf
sql_query = SELECT SQL_NO_CACHE catalog_products.id * 2 + 0 AS id, catalog_products.title AS title, catalog_products.authors AS authors, catalog_products.id AS id, catalog_products.sku AS sku_field, GROUP_CONCAT(DISTINCT catalog_authors.first_name SEPARATOR ' ') AS writer_first_name, catalog_products.id AS sphinx_internal_id, 'Catalog::Product' AS sphinx_internal_class, 0 AS sphinx_deleted, UNIX_TIMESTAMP(catalog_products.created_at) AS created_at, catalog_products.available AS available, catalog_products.price AS price, catalog_products.sku AS sku FROM catalog_products LEFT OUTER JOIN catalog_authors ON catalog_authors.product_id = catalog_products.id WHERE (catalog_products.id BETWEEN $start AND $end) GROUP BY catalog_products.id, catalog_products.title, catalog_products.authors, catalog_products.id, catalog_products.sku, catalog_products.id, catalog_products.created_at, catalog_products.available, catalog_products.price, catalog_products.sku ORDER BY NULL
присуствует строка
LEFT OUTER JOIN catalog_authors ON catalog_authors.product_id = catalog_products.id
видемо сфинкс не правильно определяет связь!?
Как правильно добавить связь has_and_belongs_to_many в индекс?
Заранее спасибо))