Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADMIN API: error when try to sort destinations by country.name #1300

Closed
Ivanov-Anton opened this issue Jun 21, 2023 · 1 comment · Fixed by #1299
Closed

ADMIN API: error when try to sort destinations by country.name #1300

Ivanov-Anton opened this issue Jun 21, 2023 · 1 comment · Fixed by #1299
Assignees

Comments

@Ivanov-Anton
Copy link
Collaborator

Description

When I execute request GET /api/rest/admin/routing/destinations?sort=country.name app crashes because the country relationship does not belong to the destination directly but through network_prefix (see code sniped below).

class Routing::Destination < ApplicationRecord
  belongs_to :network_prefix, class_name: 'System::NetworkPrefix', optional: true
  has_one :country, through: :network_prefix
end

class Api::Rest::Admin::Routing::DestinationResource < ::BaseResource
  has_one :country, class_name: 'Country', force_routed: true, foreign_key_on: :related
end

I suggest overriding the sort_records class method to perform such sorting

Additional info

backtrace error when executing a request with sorting by country.name

SELECT "class4"."destinations".* FROM "class4"."destinations"
LEFT JOIN sys.countries AS country_sorting ON country_sorting.id = class4.destinations.country_id
LEFT JOIN class4.rate_groups AS rate_group_sorting ON rate_group_sorting.id = class4.destinations.rate_group_id
ORDER BY country_sorting.name asc, rate_group_sorting.name asc LIMIT $1 OFFSET $2  [["LIMIT", 50], ["OFFSET", 0]]


Internal Server Error: PG::UndefinedColumn: ERROR:  column destinations.country_id does not exist
LINE 1: ...ntries AS country_sorting ON country_sorting.id = class4.des...
                                                             ^
@Ivanov-Anton
Copy link
Collaborator Author

related issue cerebris/jsonapi-resources#1409

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant