Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/jsonapi/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,8 @@ def _build_joins(associations)
joins = []

associations.inject do |prev, current|
joins << "LEFT JOIN #{current.table_name} AS #{current.name}_sorting ON #{current.name}_sorting.id = #{prev.table_name}.#{current.foreign_key}"
relationship_primary_key = current.options.fetch(:primary_key, "id")
joins << "LEFT JOIN #{current.table_name} AS #{current.name}_sorting ON #{current.name}_sorting.#{relationship_primary_key} = #{prev.table_name}.#{current.foreign_key}"
current
end
joins.join("\n")
Expand Down
Loading