thinking sphinx using association model as a boolean field while building index.

64 views
Skip to first unread message

mohitnegi

unread,
Feb 2, 2012, 8:58:14 AM2/2/12
to thinkin...@googlegroups.com
Hi,

I have 3 model (A,B and C) and the association is like

In A
   has_one :B, :class_name => ' ', :foreign_key => :a_id
   has_one :C, :class_name =>' ', :foreign_key => :id

In B
   belongs_to :A, :class_name => ' ', :foreign_key => :a_id

In C
   belongs_to :A, :foreign_key => 'id' 
   has_one :C, :class_name=>' ', :through=>:a, :foreign_key=>:id


Now i have defined my index in model B.as

has "COUNT(DISTINCT c.id) > 0", :as => :has_c, :type=> :boolean

I want that if a set of records in model A has record in model C also then in my index definition the boolean field has_c should be true else false.

But as i run 
bundle exec rake ts:rebuild it gives following error

Unknown column 'c.id' in 'field list'

Pat Allan

unread,
Feb 2, 2012, 8:32:14 PM2/2/12
to thinkin...@googlegroups.com

You'll need to force the join on the association - add this to your define_index block:

join a.c

--
Pat

> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/thinking-sphinx/-/a9l2O35Y06AJ.
> To post to this group, send email to thinkin...@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.

Reply all
Reply to author
Forward
0 new messages