複数の「has_many through」関係を持つ Rails モデルがあります。これらをアクティブ レコードと検索可能ブロックで定義しました。1 語のモデル名 (例: Contributor) でリレーションシップを定義し、インデックスを再作成すると、正常に機能します。2 語のモデル名 (例: LuSubject) でリレーションシップを定義して再インデックスすると、機能しません。「undefined method 'subject_ids'」というエラーが表示されます。同じ結果で他のモデルを試しました。「Award」は機能しますが、「LuGrade」は機能しません。
私の「仕事」モデルのコードは次のとおりです。
class Work < ActiveRecord::Base
self.table_name = 'work'
self.primary_keys = :WORK_ID
alias_attribute :work_id, :WORK_ID
alias_attribute :title, :TITLE
alias_attribute :series_id, :SERIES_ID
has_many :work_contributors, :foreign_key => :WORK_ID
has_many :contributors, :through => :work_contributors
has_many :work_grades, :foreign_key => :WORK_ID
has_many :lu_grades, :through => :work_grades
has_many :work_primary_subjects, :foreign_key => :WORK_ID
has_many :lu_subjects, :through => :work_primary_subjects
has_many :work_awards, :foreign_key => :WORK_ID
has_many :awards, :through => :work_awards
belongs_to :series, :foreign_key => :SERIES_ID
searchable do
text :title
integer :work_id
string :title
integer :series_id
integer :contributor_ids, :references => Contributor, :multiple => true
integer :subject_ids, :references => LuSubject, :multiple => true
end
reindex コマンドの出力は次のとおりです。
$ bundle exec rake sunspot:reindex
rake aborted!
undefined method `subject_ids' for #<Work:0x00000003bee760>
Tasks: TOP => sunspot:reindex
(See full trace by running task with --trace)
ここに完全なトレースがあります
$ bundle exec rake sunspot:reindex --trace
** Invoke sunspot:reindex (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute sunspot:reindex
rake aborted!
undefined method `subject_ids' for #<Work:0x00000004001690>
/var/lib/gems/1.9.1/gems/activemodel-3.2.6/lib/active_model/attribute_methods.rb:407:in `method_missing'
/var/lib/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/attribute_methods.rb:149:in `method_missing'
/var/lib/gems/1.9.1/gems/sunspot-1.3.3/lib/sunspot/data_extractor.rb:17:in `value_for'
/var/lib/gems/1.9.1/gems/sunspot-1.3.3/lib/sunspot/field_factory.rb:58:in `populate_document'
/var/lib/gems/1.9.1/gems/sunspot-1.3.3/lib/sunspot/indexer.rb:95:in `block in prepare '
/var/lib/gems/1.9.1/gems/sunspot-1.3.3/lib/sunspot/indexer.rb:94:in `each'
/var/lib/gems/1.9.1/gems/sunspot-1.3.3/lib/sunspot/indexer.rb:94:in `prepare'
/var/lib/gems/1.9.1/gems/sunspot-1.3.3/lib/sunspot/indexer.rb:24:in `block in add'
/var/lib/gems/1.9.1/gems/sunspot-1.3.3/lib/sunspot/indexer.rb:24:in `map'
/var/lib/gems/1.9.1/gems/sunspot-1.3.3/lib/sunspot/indexer.rb:24:in `add'
/var/lib/gems/1.9.1/gems/sunspot-1.3.3/lib/sunspot/session.rb:91:in `index'
/var/lib/gems/1.9.1/gems/sunspot- 1.3.3/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `index'
/var/lib/gems/1.9.1/gems/sunspot- 1.3.3/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb:17:in `method_missing'
/var/lib/gems/1.9.1/gems/sunspot-1.3.3/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `index'
/var/lib/gems/1.9.1/gems/sunspot-1.3.3/lib/sunspot.rb:184:in `index'
/var/lib/gems/1.9.1/gems/sunspot_rails-1.3.3/lib/sunspot/rails/searchable.rb:256:in `block (2 levels) in solr_index'
/var/lib/gems/1.9.1/gems/sunspot_rails-1.3.3/lib/sunspot/rails/searchable.rb:345:in `solr_benchmark'
/var/lib/gems/1.9.1/gems/sunspot_rails-1.3.3/lib/sunspot/rails/searchable.rb:255:in `block in solr_index'
/var/lib/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/relation/batches.rb:72:in `find_in_batches'
/var/lib/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/querying.rb:8:in `find_in_batches'
/var/lib/gems/1.9.1/gems/sunspot_rails-1.3.3/lib/sunspot/rails/searchable.rb:254:in `solr_index'
/var/lib/gems/1.9.1/gems/sunspot_rails-1.3.3/lib/sunspot/rails/searchable.rb:198:in `solr_reindex'
/var/lib/gems/1.9.1/gems/sunspot_rails-1.3.3/lib/sunspot/rails/tasks.rb:58:in `block (3 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/sunspot-1.3.3/lib/sunspot/class_set.rb:16:in `each'
/var/lib/gems/1.9.1/gems/sunspot-1.3.3/lib/sunspot/class_set.rb:16:in `each'
/var/lib/gems/1.9.1/gems/sunspot_rails-1.3.3/lib/sunspot/rails/tasks.rb:57:in `block (2 levels) in <top (required)>'
/usr/lib/ruby/vendor_ruby/rake/task.rb:205:in `call'
/usr/lib/ruby/vendor_ruby/rake/task.rb:205:in `block in execute'
/usr/lib/ruby/vendor_ruby/rake/task.rb:200:in `each'
/usr/lib/ruby/vendor_ruby/rake/task.rb:200:in `execute'
/usr/lib/ruby/vendor_ruby/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/lib/ruby/vendor_ruby/rake/task.rb:151:in `invoke_with_call_chain'
/usr/lib/ruby/vendor_ruby/rake/task.rb:144:in `invoke'
/usr/lib/ruby/vendor_ruby/rake/application.rb:116:in `invoke_task'
/usr/lib/ruby/vendor_ruby/rake/application.rb:94:in `block (2 levels) in top_level'
/usr/lib/ruby/vendor_ruby/rake/application.rb:94:in `each'
/usr/lib/ruby/vendor_ruby/rake/application.rb:94:in `block in top_level'
/usr/lib/ruby/vendor_ruby/rake/application.rb:133:in `standard_exception_handling'
/usr/lib/ruby/vendor_ruby/rake/application.rb:88:in `top_level'
/usr/lib/ruby/vendor_ruby/rake/application.rb:66:in `block in run'
/usr/lib/ruby/vendor_ruby/rake/application.rb:133:in `standard_exception_handling'
/usr/lib/ruby/vendor_ruby/rake/application.rb:63:in `run'
/usr/bin/rake:27:in `<main>'
Tasks: TOP => sunspot:reindex
ここに私の現在のバージョン情報があります
$ gem list|grep sunspot
sunspot (1.3.3)
sunspot_rails (1.3.3)
sunspot_solr (1.3.3)
注: 私は実稼働テーブルで作業しているため、これらのテーブルの名前を変更するオプションはありません。
ありがとう。