Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Conversation

@babywolfh
Copy link

sort queryparams can be relationship fileds

huangzhuo added 3 commits August 15, 2018 16:01
sort queryparams can be relationship fileds
1. delete sort relationship exception
2. add a case to test get list with relationship sort queryparams
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 93.52% when pulling 05106a4 on babywolfh:sort_relationships into 268e948 on miLibris:master.

@akira-dev
Copy link
Contributor

akira-dev commented Jan 22, 2019

I think it is a good start to implement sorting on relationship fields but it would be better that you can specify the related field to sort on instead of only use to related "id" field. ex:

{'field': field, 'order': order, 'relationship_field': related_field}

if sort_opt['relationship']:
relationField = getattr(self.model, field)
relationClass = relationField.mapper.class_
query = query.join(relationField).order_by(getattr(getattr(relationClass, 'id'), sort_opt['order'])())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not good to use the id field because it can not exists. For example I never name my primary keys as id.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants