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

Unable to sort related records by fieldname #1805

Closed
peterboorsma opened this issue Sep 1, 2020 · 1 comment · Fixed by #1809
Closed

Unable to sort related records by fieldname #1805

peterboorsma opened this issue Sep 1, 2020 · 1 comment · Fixed by #1809

Comments

@peterboorsma
Copy link
Contributor

I'm trying to order a list of related records by a number field (mode: float), like this:

{% set relatedrecords = record|related('songs') %}
{% for related in relatedrecords|order('tracknumber') %}
<p>{{ related.tracknumber }}, {{ related|title }}</p>
{% endfor %}

My contenttype field:

        tracknumber:
            type: number
            mode: float

But my list of records does not follow the ordering I want.

There is a dirty workaround for those who need it quickly, like moi :)

{% set relatedrecords = record|related('songs')|sort((a,b) => a.tracknumber <=> b.tracknumber) %}
{% for related in relatedrecords %}
...
{% endfor %}
@bobdenotter
Copy link
Member

Tagged as documentation issue, thanks!

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

Successfully merging a pull request may close this issue.

3 participants