TS has a method for forcing a join:

  join lessons

That way you shouldn't need the field (which should also work as an integer - 
no idea why it doesn't for you).

-- 
Pat

On 05/02/2011, at 6:50 AM, Benjamin Moses Lieb wrote:

> I get unknown column error when I do this. Looking through the config
> generated SQL, I can see that the lessons table is not being joined. I
> don't know how to manually add another join, but my workaround was to
> add
> 
>    indexes lessons(:id), :as => :lesson_shim, :type => :integer
> #necessary for :lessons to work, do NOT make this an attribute!
> 
> This seems to add the proper join bit to the SQL, but doesn't work as
> expected if I use has instead of indexes.
> 
> Is there a better, smarter way to add a join?
> 
> 
> On Feb 2, 11:08 pm, Pat Allan <[email protected]> wrote:
>> TS doesn't have a count function built-in, so you're going to have to break 
>> out the SQL:
>> 
>>   has "COUNT(lessons.id)", :as => :num_lessons, :type => :integer
>> 
>> Give that a shot.
>> 
>> Cheers
>> 
>> --
>> Pat
>> 
>> On 03/02/2011, at 2:47 PM, Benjamin Moses Lieb wrote:
>> 
>>> In my site I would like to be able to sort the "lesson packs" by the
>>> number of lessons they contain.
>> 
>>>  define_index do
>>>    indexes :name, :sortable => true
>>>    indexes :description
>>>    indexes [ lessons.instructors.first_name,
>>> lessons.instructors.last_name ], :as => "instructor_name", :sortable
>>> => true
>>>    has :created_at, :status
>>>    has lessons.count, :as => :num_lessons
>>>  end
>> 
>>> The line:
>> 
>>> has lessons.count, :as => :num_lessons
>> 
>>> doesn't work. This seems like a common/simple issue, but I cannot
>>> figure out how to do it.
>> 
>>> All help appreciated.
>> 
>>> --
>>> 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 
>>> athttp://groups.google.com/group/thinking-sphinx?hl=en.
> 
> -- 
> 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.
> 

-- 
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