views:

436

answers:

1

I have a model:

class Topic < ActiveRecord::Base

  define_index do 
    indexes title, :sortable => true
    indexes body
    indexes tags(:name), :as => :tag_name
  end

  has_and_belongs_to_many :tags, :join_table => 'topic_tags', :order => 'tags.name asc'

end

When I run:

rake ts:rebuild

I get:

sql_range_query: Unknown column 'topics.name' in 'field list'

And my 'config/development.sphinx.conf' has this oddness:

  sql_query = SELECT `topics`.`id` * 1 + 0 AS `id` , CAST(`topics`.`title` AS CHAR) AS 
`title`, CAST(`topics`.`body` AS CHAR) AS `body`, CAST(`topics`.`name` AS CHAR) AS 
`tag_name`, `topics`.`id` AS `sphinx_internal_id`, 1552019743 AS `class_crc`, '1552019743'
 AS `subclass_crcs`, 0 AS `sphinx_deleted`, IFNULL(`topics`.`title`, '') AS `title_sort` 
FROM `topics`    WHERE `topics`.`id` >= $start AND `topics`.`id` <= $end GROUP BY 
`topics`.`id`  ORDER BY NULL
  sql_query_range = SELECT IFNULL(MIN(`id`), 1), IFNULL(MAX(`id`), 1) FROM `topics`

So for some reason associations look bust, where have I gone wrong and how do I fix this?

(running rails 2.3.4 and latest thinking sphinx 1.2.11)

+4  A: 

Trivial trap:

This works:

class Topic < ActiveRecord::Base
  has_and_belongs_to_many :tags, :join_table => 'topic_tags', :order => 'tags.name asc'

  define_index do 
    indexes title, :sortable => true
    indexes body
    indexes tags(:name), :as => :tag_name
  end



end

associations must be defined prior to the index.

Sam Saffron