2009-09-22 46 views
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: Unknown column 'topics.name' in 'field list'

而我的「配置/發展。 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` 

所以由於某些原因,協會看起來破產,我哪裏出錯了,我該如何解決這個問題?

(運行軌道2.3.4和最新思想獅身人面像1.2.11)

回答

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 

協會必須先於指數來定義。