1

私はモデルを持っています:

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

私が実行すると:

rake ts:rebuild

私は得る:

sql_range_query: 「フィールド リスト」の不明な列「topics.name」

そして、私の「config/development.sphinx.conf」には次のような奇妙な点があります:

  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`

なんらかの理由でアソシエーションが機能していないように見えますが、どこが間違っていて、どうすれば修正できますか?

(Rails 2.3.4 と最新の Thinking Sphinx 1.2.11 を実行)

4

1 に答える 1

9

些細な罠:

これは機能します:

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

アソシエーションは、インデックスの前に定義する必要があります。

于 2009-09-22T01:54:49.973 に答える