我需要加入并以json格式从三个表中获取结果
@employee = Employee.joins(:salary,:personal_info).select("salary.*,personal_info.*) --> This works fine
@employee = Employee.joins(:salary,:personal_info,:loan).select("salary.*,personal_info.*,loan.*) --> only salary and personal_info is coming
format.json { render json: @employee, serializer: EmployeeSerializer, :root => 'employee'}
答案 0 :(得分:0)
通过提供原始sql来尝试这个,
@employee = Employee.joins('INNER JOIN salary ON salary.employee_id = employee.id INNER JOIN personal_info ON personal_info.employee_id = employee.id INNER JOIN loan ON loan.employee_id = employee.id')