title: Rails 4.1 and Thinking Sphinx - undefined method 'parent' for ActiveRecord::Associations::JoinDependency::JoinAssociation
body: <p>I started to upgrade <code>Rails 4.0</code> app to <code>Rails 4.1</code>. App uses a lot of gems and Thinking Sphinx is one of them. I have reinstalled thinking-sphinx gem after Rails 4.1 upgrade (to enable proper version of joiner, which is <code>3.0</code> now). But now I get weird error from TS when I try, for example, to rebuild index:</p>
  
  <pre><code>$ rake ts:rebuild --trace
  ** Invoke ts:rebuild (first_time)
  ** Invoke ts:stop (first_time)
  ** Invoke environment (first_time)
  ** Execute environment
  ** Execute ts:stop
  searchd is not currently running.
  Stopped searchd daemon (pid: ).
  ** Invoke ts:index (first_time)
  ** Invoke environment 
  ** Execute ts:index
  Generating configuration to /Users/serj/Projects/project/config/development.sphinx.conf
  rake aborted!
  NoMethodError: undefined method `parent' for #&lt;ActiveRecord::Associations::JoinDependency::JoinAssociation:0x007ff438543678&gt;
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/filtered_reflection.rb:40:in `block in scope'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency/join_association.rb:52:in `instance_exec'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency/join_association.rb:52:in `block (2 levels) in join_constraints'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency/join_association.rb:48:in `map'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency/join_association.rb:48:in `block in join_constraints'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency/join_association.rb:33:in `reverse_each'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency/join_association.rb:33:in `join_constraints'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency.rb:161:in `make_constraints'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency.rb:167:in `make_outer_joins'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency.rb:169:in `block in make_outer_joins'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency.rb:169:in `each'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency.rb:169:in `flat_map'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency.rb:169:in `make_outer_joins'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency.rb:205:in `block in walk'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency.rb:205:in `each'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency.rb:205:in `flat_map'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency.rb:205:in `walk'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency.rb:114:in `block in join_constraints'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency.rb:112:in `each'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency.rb:112:in `flat_map'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/associations/join_dependency.rb:112:in `join_constraints'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/relation/query_methods.rb:985:in `build_joins'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/relation/query_methods.rb:838:in `build_arel'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/relation/query_methods.rb:830:in `arel'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/activerecord-4.1.1/lib/active_record/relation.rb:520:in `to_sql'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_builder.rb:11:in `sql_query'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:119:in `build_sql_query'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:136:in `prepare_for_render'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:65:in `render'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/riddle-1.5.11/lib/riddle/configuration/index.rb:29:in `block in render'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/riddle-1.5.11/lib/riddle/configuration/index.rb:29:in `collect'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/riddle-1.5.11/lib/riddle/configuration/index.rb:29:in `render'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/core/index.rb:53:in `render'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/riddle-1.5.11/lib/riddle/configuration.rb:43:in `block in render'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/riddle-1.5.11/lib/riddle/configuration.rb:43:in `collect'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/riddle-1.5.11/lib/riddle/configuration.rb:43:in `render'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:90:in `render'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `block in render_to_file'
  /Users/serj/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/open-uri.rb:36:in `open'
  /Users/serj/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/open-uri.rb:36:in `open'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `render_to_file'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/rake_interface.rb:13:in `configure'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/rake_interface.rb:24:in `index'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/tasks.rb:9:in `block (2 levels) in &lt;top (required)&gt;'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
  /Users/serj/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/task.rb:201:in `block in invoke_prerequisites'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/task.rb:199:in `each'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/task.rb:199:in `invoke_prerequisites'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
  /Users/serj/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/application.rb:150:in `invoke_task'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/gems/rake-10.3.2/bin/rake:33:in `&lt;top (required)&gt;'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/bin/rake:23:in `load'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/bin/rake:23:in `&lt;main&gt;'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/bin/ruby_executable_hooks:15:in `eval'
  /Users/serj/.rvm/gems/ruby-2.0.0-p353@project/bin/ruby_executable_hooks:15:in `&lt;main&gt;'
  Tasks: TOP =&gt; ts:rebuild =&gt; ts:index
  </code></pre>
  
  <p><strong>Gemfile</strong></p>
  
  <pre><code>source 'http://rubygems.org'
  
  gem 'rails', '4.1.0'
  
  # Sphinx.
  gem 'mysql2',          '0.3.13', platform: :ruby
  gem 'thinking-sphinx', '~&gt; 3.1.1'
  
  # ...
  </code></pre>
  
  <p><strong>thinking_sphinx.yml</strong></p>
  
  <pre><code>development: &amp;defaults
    morphology: stem_enru, Soundex, Metaphone
    enable_star: 1
    expand_keywords: 1
    min_infix_len: 2
    max_matches: 500000
  
  test:
    mysql41: &lt;%= ENV['TEST_ENV_NUMBER'].to_i + 9307 %&gt;
    pid_file: &lt;%= File.join(Rails.root, "tmp", "searchd.#{ENV['TEST_ENV_NUMBER']}.pid") %&gt;
    indices_location: &lt;%= File.join(Rails.root, "db", "sphinx", "#{ENV['TEST_ENV_NUMBER']}") %&gt;
    configuration_file: &lt;%= File.join(Rails.root, "config", "test.#{ENV['TEST_ENV_NUMBER']}.sphinx.conf") %&gt;
    binlog_path: &lt;%= File.join(Rails.root, "db", "sphinx", "#{ENV['TEST_ENV_NUMBER']}", "binlog") %&gt;
    &lt;&lt;: *defaults
  </code></pre>
  
  <p>Additional data:</p>
  
  <ul>
  <li>Rails 4.1</li>
  <li>Sphinx 2.1.4-release (rel21-r4421)</li>
  <li>thinking-sphinx 3.1.1</li>
  <li>mysql2 0.3.16 (for sphinx)</li>
  <li>pg 0.17.1 (it's my main database)</li>
  </ul>
  
  <p>Any ideas how to deal with that? I can't make the upgrade to new Rails, because the project uses TS very heavy.</p>