title: Conditional issue using relationship
body: <p>I'm trying to search a column from another table using three tables in relationship.</p>
  
  <p>In my view <code>policy_vehicles</code> I have a <code>text_field_tag</code> and want to search by "raz_soc".</p>
  
  <p>My tables are:</p>
  
  <pre><code>Policy_vehicles
     |id|       |policy_id| 
      integer      integer
       100            1 
       200            2
  
  Policies
     |id|    |client_id|
     integer  integer
      1        1
      2        2     
  
  Clients
     |id|     |raz_soc|
      integer  varchar(255)
      1       MARATEX SAC
      2       ATT
  </code></pre>
  
  <p>This is my controller:</p>
  
  <pre><code>class PolicyManagement::PolicyController &lt; ApplicationController
  
    def generate_print_per_vehicle
        params[:search_policy_id] =   Policy.find(:all,:joins =&gt; :client ,:conditions =&gt; ['raz_soc LIKE ?',"%#{params[:search_raz_soc]}%"  ])
        @policies= PolicyVehicle.find(:all,:joins =&gt; :policy, :conditions =&gt; ['policy_id = ?',params[:search_policy_id] ]) 
    end
  
  end
  </code></pre>
  
  <p>This is my model:</p>
  
  <pre><code>class Policy &lt; ActiveRecord::Base
    belongs_to :client
    has_many :policy_vehicles
  end
  
  class PolicyVehicle &lt; ActiveRecord::Base
    belongs_to :policy
  end
  
  class Client &lt; ActiveRecord::Base
    has_many :policies
  end
  </code></pre>
  
  <p>This is my view where I'm trying to find by a column from another table:</p>
  
  <pre><code>&lt;% form_tag :controller=&gt;"policy_management/policy",:action=&gt;"generate_print_per_vehicle" do %&gt;
   Society:
     &lt;%= text_field_tag "search_raz_soc",params[:search_raz_soc] %&gt;
     &lt;%= submit_tag "Buscar", :name =&gt; nil %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>My logs are:</p>
  
  <pre><code>  Mysql::Error: Operand should contain 1 column(s): SELECT `policy_vehicles`.* FROM `policy_vehicles`   INNER JOIN `policies` ON `policies`.id = `policy_vehicles`.policy_id  WHERE (policy_id = 166,1540,2822,4074)
  </code></pre>
  
  <p>It should be a search like this:</p>
  
  <pre><code> Policy Load (3.1ms)   SELECT `policies`.* FROM `policies` INNER JOIN `clients` ON `clients`.id = `policies`.client_id WHERE (raz_soc = 'MARATEX SAC') 
   PolicyVehicle Load (0.3ms)   SELECT `policy_vehicles`.* FROM `policy_vehicles` INNER JOIN `policies` ON `policies`.id = `policy_vehicles`.policy_id WHERE (policy_id = 1) 
  </code></pre>
  
  <p>I tried this but is not working:</p>
  
  <pre><code> #controller
   @policy =         Policy.find(:all,:joins =&gt; :client ,:conditions =&gt; ['raz_soc LIKE ?',params[:search_raz_soc]  ])
   @policies= PolicyVehicle.find(:all,:joins =&gt; :policy, :conditions =&gt; ['policy_id = ?',@policy    ])
  
  #logs
   Policy Load (3.1ms)   SELECT `policies`.* FROM `policies` INNER JOIN `clients` ON `clients`.id = `policies`.client_id WHERE (raz_soc = 'MARATEX SAC') 
   PolicyVehicle Load (0.3ms)   SELECT `policy_vehicles`.* FROM `policy_vehicles` INNER JOIN `policies` ON `policies`.id = `policy_vehicles`.policy_id WHERE (policy_id = 70353610714140) 
  </code></pre>
  
  <p>I'm trying to do something like this</p>
  
  <pre><code> select * from policy_vehicles where policy_id
      IN ( SELECT id FROM policies WHERE
      client_id IN (SELECT id FROM clients raz_soc = ?) )
  </code></pre>
  
  <p>Can someone can help me please? </p>