So I think what you want is the following:

  # for PostgreSQL:
  has "bool_and(courses.is_visible)", as: :is_visible, type: :boolean
  # for MySQL:
  has "IF(SUM(courses.is_visible) = COUNT(courses.is_visible), 1, 0)", as: 
:is_visible, type: :boolean

Not entirely sure about the MySQL version, given Rails uses small integers 
instead of a boolean type... worth double-checking... but essentially we're 
just falling back to SQL here, which is why we need to explicitly supply a type 
(using database columns normally, TS can figure it out).

Does that help?

-- 
Pat

On 17 Jun 2014, at 11:12 pm, Daniel Gottschalck <[email protected]> wrote:

> Hi Pat
> 
> Projects with only visible courses is what I need.
> 
> If I do:
> 
> has courses.is_visible, as: :is_visible
> 
> Then I'm getting an error about it expects a uint,  bigint or something else.
> 
> Regards
> 
> Den 17/06/2014 23.00 skrev "Pat Allan" <[email protected]>:
> Hi Daniel
> 
> I'm not quite sure what results you're expecting... projects with *only* 
> visible courses? projects with at least one visible course? or something else?
> 
> But also, on a general level - boolean values like this definitely should be 
> attributes - so, the `has` method, and are filtered using the `with` option.
> 
> Cheers
> 
> -- 
> Pat
> 
> On 17 Jun 2014, at 8:56 pm, Daniel Gottschalck <[email protected]> wrote:
> 
>> Hey
>> 
>> 
>> In the website, there is "projects", and "projects" can have "courses".
>> 
>> 
>> In my project index file, how would I filter on "courses" which "is_visible" 
>> true?
>> 
>> Im confused on whether to use "has" or "indexes" for a relation model 
>> boolean value.
>> 
>>  
>> ThinkingSphinx::Index.define 'refinery/wayfinders/project', :with => 
>> :active_record do
>>      indexes :name, sortable: true
>>      indexes :city
>>      indexes :description
>>      indexes courses.name, as: :course_name
>> 
>>      indexes courses.is_visible, as: :is_visible <------------------------ 
>> This one?
>> 
>>      set_property :group_concat_max_len => 8192
>>      has zip, external_id
>>  
>>      has courses.is_visible, as: :is_visible, type: :boolean 
>> <------------------- Or this one?
>> end
>> 
>> And how would I then filter it in my search_controller? So I only get 
>> courses which are visible?
>> 
>> @project_search = Refinery::Wayfinders::Project.search(params[:search], 
>> :with => { :is_visible => true }) 
>> 
>> 
>> OR
>> 
>> @project_search = Refinery::Wayfinders::Project.search(params[:search], 
>> :include => :is_visible, :conditions => { :is_visible => true })
>> 
>> 
>> Or a third solution?
>> 
>> 
>> Thanks in advance
>> 
>> 
>> Regards 
>>  
>> 
>> -- 
>> 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/d/optout.
> 
> 
> -- 
> You received this message because you are subscribed to a topic in the Google 
> Groups "Thinking Sphinx" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/thinking-sphinx/IoYl27QsSVI/unsubscribe.
> To unsubscribe from this group and all its topics, 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/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 http://groups.google.com/group/thinking-sphinx.
> For more options, visit 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 http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.

Reply via email to