Pregunta

I did a search using the gem "thinking_sphinx", version => '1.4.14'.

I'm trying to create conditional in my table policy where policies.deleted= 0

Here is my controller

 class PolicyController < ApplicationController

    def search
      @policies = Policy.search params[:search],:conditions=>[policies.deleted=0] :include => :client, :match_mode => :boolean
    end

 end

My models are : "Policy" and "Client"

class Policy < ActiveRecord::Base
   belongs_to :client

   define_index 'policy_foo' do
      indexes mum_policy
      indexes [client.name, client.lastname1], :as => :client_name
      has client_id, created_at
   end
end

class Client < ActiveRecord::Base
  has_many  :policies
end

I tried

    def search
        @policies = Policy.search params[:query],:include => :client, :match_mode => :boolean   
        @search = Policy.find(:all,:conditions=>['deleted=0 and client_id IN (?)',@client])
    end

Somebody knows how to search and condition deleted= 0?

I will really appreciate help

¿Fue útil?

Solución

You'll need to have deleted as an attribute available in your index definition:

define_index 'policy_foo' do
  indexes mum_policy
  indexes [client.name, client.lastname1], :as => :client_name

  has client_id, created_at, deleted
end

And then the following will work:

Policy.search params[:query], :include => :client, :match_mode => :boolean,
  :with => {:deleted => 0, :client_id => @client.id}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top