0

我需要以 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'}
4

1 回答 1

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')
于 2013-08-07T11:09:48.047 回答