2016-04-07 9 views
0

数字のCPFがすべての結果を表示する検索があります。 [OK]を、私はそのショーをこのように必要があります。 (ただ、人とそれを持っている契約の数量) *私のコードは、ポルトガル語で数字cpfに複製値を問い合わせてください

Name 
Registry 
CPF 
    Contract 1 ---- Show all contracts 
    Contract 2 -------- 
    Contract 3 ----------- 

に残念です。しかし、それは現在ので来ている: (契約の量)に応じて同じ値

Name 
Registry 
CPF 
    Contract 1 ---- Show all contracts 
    Contract 2 -------- 
    Contract 3 ----------- 

Name 
Registry 
CPF 
    Contract 1 ---- Show all contracts 
    Contract 2 -------- 
    Contract 3 ----------- 

Name 
Registry 
CPF 
    Contract 1 ---- Show all contracts 
    Contract 2 -------- 
    Contract 3 ----------- 

契約者数は

私の見解はこれです...ので、値を複製している:

01この中
<% if params[:pesquisa_func_cpf].present? %> 
    <h4><b>Resultados</b></h4> 
    <% @autorizacoes.each do |autorizacao| %> 
    <table class="table table-condensed"> 
     <tr> 
     <th>Name</th> 
     <td><%= autorizacao.employee.person.name %></td> 
     </tr> 
     <tr> 
     <th>Registry</th> 
     <td><%= autorizacao.employee.registry %></td> 
     </tr> 
     <tr> 
     <th>CPF</th> 
     <td><%= autorizacao.employee.person.cpf %></td> 
     </tr> 
    </table> 
    <hr /> 
    <table class="table table-condensed table-bordered"> 
     <th>Contract number</th> 
     <% @autorizacoes.each do |autorizacao| %> 
     <td><%= autorizacao.number_contract %></td> 
     <% end %> 
    </table> 

    <% end %> 
<% end%> 

は私のコントローラです:

場合のparams [:pesquisa_func_cpf] .present? @autorizacoes = Autorizacao.pesquisa_func_cpf(のparams [:pesquisa_func_cpf])。全て

私が代わりに.ALLの.distinctを試してみたが、動作しません:(

そして、私(I Oracleを使用)相談し、

select * from autorizacoes INNER JOIN employers ON employers.id = autorizacoes.employer_id 
          INNER JOIN people ON employers.person_id = people.id 
          WHERE people.cpf LIKE '111.111.111-11' 

そして、それは3つの結果を返す、私の例に従って、どのようにちょうどこの構造を残してください:それはある!

Name 
Registry 
CPF 
    Contract 1 ---- Show all contracts 
    Contract 2 -------- 
    Contract 3 ----------- 

答えて

0

私はそれを得た私のコ​​ントローラでは、私はちょうどこの:

if params[:pesquisa_func_cpf].present? 
     @employers = Employee.pesquisa_cpf(params[:pesquisa_func_cpf]).all 
     @autorizacoes = Autorizacao.pesquisa_func_cpf(params[:pesquisa_func_cpf]).all 

そして、私のビュー私は<% = autorizacao.employee.person.name%>を削除して、ちょうどこの作品と<% = employee.person.name%>

を入れて!

関連する問題