如何使用 join 咨询 SQL 以及在何处查看 rails
How do consult SQL with join and where and put it in view on rails
我有:
person 有很多雇员
员工属于个人,有很多再融资
再融资属于员工
Person 有一个名为 cpf (uniq) 的列
Employee 有一个名为 register
的列
我如何为一个 WHERE in view Refinancing return all registers this cpf??
我正在尝试这个:
select * from refinancings join (employees)
on (refinancings.employee_id = employee.id)
join (people)
on (employees.person_id = people.id)
where (cpf = 111111)
但是,这个 return 这个 cpf 的所有再融资
我需要全部注册这个cpf。怎么做到的?
在此之后我需要放在这里:
<%= f.association :employee, collection: Employee.all, label_method: :register, value_method: :id, prompt: "Select a register" %>
- CPF没关系,我在URL
中取uby参数
我明白了!
SQL:
select * from funcionarios join (pessoas)
on (funcionarios.pessoa_id = pessoas.id)
where (cpf = '111.111.111-11')
Rails:
Funcionario.joins(:pessoa).where("pessoas.cpf" => params[:pesquisa_func_cpf])
我有:
person 有很多雇员 员工属于个人,有很多再融资 再融资属于员工
Person 有一个名为 cpf (uniq) 的列 Employee 有一个名为 register
的列我如何为一个 WHERE in view Refinancing return all registers this cpf?? 我正在尝试这个:
select * from refinancings join (employees)
on (refinancings.employee_id = employee.id)
join (people)
on (employees.person_id = people.id)
where (cpf = 111111)
但是,这个 return 这个 cpf 的所有再融资 我需要全部注册这个cpf。怎么做到的?
在此之后我需要放在这里:
<%= f.association :employee, collection: Employee.all, label_method: :register, value_method: :id, prompt: "Select a register" %>
- CPF没关系,我在URL 中取uby参数
我明白了!
SQL:
select * from funcionarios join (pessoas)
on (funcionarios.pessoa_id = pessoas.id)
where (cpf = '111.111.111-11')
Rails:
Funcionario.joins(:pessoa).where("pessoas.cpf" => params[:pesquisa_func_cpf])