0

我在使用 JRuby 和 Sunspot 在 Rails 中建立索引时遇到问题。我有一个包含参考数据的附加数据库,以及与其中一个表关联的模型。这就是我的 database.yml 的样子:

# regular stuff
# ...
# reference database
snomed:
  adapter: jdbcmysql
  encoding: utf8
  hostname: localhost
  database: snomedct
  username: user
  password: pass
  socket: /tmp/mysql.sock
  pool: 5
  timeout: 5000

这就是我对该数据库的模型的样子:

class SnomedMaster < ActiveRecord::Base

  establish_connection "snomed"
  self.table_name = "curr_description_f"

  attr_accessible :effectivetime, :active, :moduleid, :conceptid, :languagecode, :typeid, :term, :casesignificanceid 

  searchable do
    text :term
  end

end

但是,当我尝试通过在 rails 控制台中运行SnomedMaster.index或rake sunspot:reindex来索引字段时,它不起作用。问题似乎在这里(来自跟踪日志):

SELECT `curr_description_f`.* FROM `curr_description_f` WHERE (`curr_description_f`.`` >= 0) ORDER BY `curr_description_f`.`` ASC LIMIT 50
ActiveRecord::JDBCError: Unknown column 'curr_description_f.' in 'where clause': SELECT  `curr_description_f`.* FROM `curr_description_f`  WHERE (`curr_description_f`.`` >= 0) ORDER BY `curr_description_f`.`` ASC LIMIT 50

我不知道太阳黑子为什么要访问列 *curr_description_f*...

谢谢

4

1 回答 1

0

我自己解决了。WHERE子句要调用:

WHERE (`curr_description_f`.`id` >= 0)

基本上,由于 sqldump 格式错误,我的数据库有一个主键的字符串 id,而且该键甚至没有分配给我的模型。这就是为什么它是空的。所以我重新创建了以INT作为主键的表,然后在我的模型中添加了一行:

self.primary_key = "id"
于 2013-07-10T05:44:07.943 回答