user has_many timesheets
timesheet has_many invoices
显示发票索引视图时,我想在其所属的
first_name
的
user
上订购发票。我可以像这样对直系父母发出命令:
Invoice.joins(:timesheet).order('timesheets.user_id')
可以再升一级吗?
Invoice.joins(timesheet: :user).order('users.first_name')
order
SQL 字符串中的列名仅包含深度嵌套的表的名称。例如:
Invoice.joins(timesheet: [user: :jobs]).order('jobs.completed_at')