Asked here
too:
http://stackoverflow.com/questions/20892716/thinking-sphinx-index-with-multiple-joins-and-conditions
---------------------------------
I have 3 models :
Class Phone < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_one :service
has_many :phones
has_many :verified_phones, -> {where('verified_at IS NOT NULL AND
destroyed_at IS NULL')}, class_name: 'Phone'
end
class Service < ActiveRecord::Base
belongs_to :user
has_many :phones, through: :user
has_many :verified_phones, through: :user
end
I'd like to define an TS-index on the model Service.
I want an boolean-faceted attribute which represents Service whose user has
one or more verified phone.
*So after reading this post
<https://groups.google.com/d/msg/thinking-sphinx/I3IxWhrexV4/fLbDSmlQjVoJ>
I tried :*
join verified_phones
has 'COUNT(verified_phones.id) > 0', as: :user_phone_verified, type:
:boolean, facet: true
but send me the error "Unknown column 'verified_phones.id' in 'field list' "
(the same error occured in the post)
*Then I tried*
join verified_phones
has 'COUNT(phones.id) > 0', as: :user_phone_verified, type: :boolean,
facet: true
-> but result are wrong : attribute is true for every user that have a
phone, verified or not, destroyed or not.
*Then I tried*
join phones
has 'COUNT(phones.verified_at IS NOT NULL AND phones.destroyed_at IS NULL)
> 0', as: :user_phone_verified, type: :boolean, facet: true
-> same problem : attribute is true for every user that have a phone,
verified or not, destroyed or not.
I'm not good with SQL syntax, could anybody help me to solve this ?
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].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/groups/opt_out.