Hi Scott

I think there are two issues here to deal with:

Firstly, method references for fields and attributes in real-time indices must 
be able to chain together in a standard Ruby way (in your example, you’re 
calling `name` on `bbc_compliances`, which is an array/association and doesn’t 
have a `name` method). The way around this would be to add the following method 
to your BbcFacility model:

  def bbc_compliance_names
    # Returning a string, as that is what Sphinx expects for fields
    bbc_compliances.collect(&:name).join(‘ ‘)
  end

And then in your index definition:

  indexes bbc_compliance_names

This is discussed in the indexing documentation under the Fields section:
http://freelancing-gods.com/thinking-sphinx/indexing.html#fields 
<http://freelancing-gods.com/thinking-sphinx/indexing.html#fields>

The second thing is actually the cause of the error you’re seeing: Sphinx is 
unaware of this field, which means you need to run `rake ts:regenerate` to 
clear out the old index files, restart Sphinx, and then re-populate with the 
new schema. This is required every time you add/change/remove fields, 
attributes or indices - it’s the rough equivalent of `rake db:migrate`.

This is covered in the rake tasks documentation in the first section (on 
ts:generate), but certainly could be more prominent!
http://freelancing-gods.com/thinking-sphinx/rake_tasks.html 
<http://freelancing-gods.com/thinking-sphinx/rake_tasks.html>

Let me know if you’ve any further questions!

— 
Pat

> On 23 Jul 2016, at 4:40 AM, Scott Macri <[email protected]> wrote:
> 
> Hello,
> 
> I'm new to sphinx and am attempting a has_many_through.  I'm using Rails 4.2 
> and Ruby 2.2.  I'm getting the following error when running config.
> ThinkingSphinx::SphinxError: unknown column: 'bbc_compliances' - REPLACE INTO 
> bbc_facility_core
> 
> Here is my setup:
> 
> ThinkingSphinx::Index.define :bbc_facility, :with => :real_time do
>    indexes name, sortable: true
>    indexes bbc_compliances.name, :as => :bbc_compliances
> end
> 
> class BbcCompliance < ActiveRecord::Base
>   has_many :bbc_facility_compliances, dependent: :destroy
>   has_many :bbc_facilities, through: :bbc_facility_compliances
> end 
> 
> class BbcFacility < ActiveRecord::Base
>   after_save ThinkingSphinx::RealTime.callback_for(:bbc_facility)
>   has_many :bbc_facility_compliances, dependent: :destroy
>   has_many :bbc_compliances, through: :bbc_facility_compliances
> end
> 
> Any help would be greatly appreciated.  Also, where can I find some 
> documentation on complex topics such as this one?  Thanks.
>   
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/thinking-sphinx 
> <https://groups.google.com/group/thinking-sphinx>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.


-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.

Reply via email to