Hello Pat,

Thank you for your reply. Referencing the ratings association in
define_index block did the trick.

-- Thuva

On May 15, 4:06 pm, Pat Allan <[email protected]> wrote:
> Hi Thuva
>
> What's the error? If you're not referencing your ratings association  
> anywhere else in your index, then it won't be there to use in the  
> manual SQL. Perhaps add the following just to make sure:
>
>    has ratings(:id), :as => :ratings_ids
>    has "AVG(ratings.value)", :as => :rating, :type => float
>
> Cheers
>
> --
> Pat
>
> On 15/05/2009, at 12:15 PM, Thuva Tharma wrote:
>
>
>
> > I have a Business model that has many ratings (in a separate table).
> > The average rating for a business is calculated as shown below:
>
> > class Business < ActiveRecord::Base
> >  has_many :ratings
>
> >  def average_rating
> >    ratings.average(:value) # value is a field in Rating model
> >  end
> > end
>
> > I would like to index the average rating for businesses via sphinx. I
> > tried the following and got an error:
>
> > has "AVG(ratings.value)", :as => :rating, :type => :float
>
> > Can someone please let me know how to approach this problem?
>
> > Thank you in advance.
>
> > -- Thuva Tharma
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to