You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I would like to know how to add customize sorting logic in has_many association?
classUserSerializer < Panko::Serializerhas_many:posts,each_serializer: PostSerializer# posts array need to be order by published_at, for exmapleendclassUser < ApplicationRecordhas_many:postsend
The text was updated successfully, but these errors were encountered:
Panko doesn't have any option to allow specific sorting in serializer, the only way you can do it - is like that:
classUserSerializer < Panko::Serializerhas_many:posts_sorted_by_created_at,name: :posts,each_serializer: PostSerializer# posts array need to be order by published_at, for exmapleendclassUser < ApplicationRecordhas_many:postsdefposts_sorted_by_created_at# Sort the posts here# Suggesting to check if `posts.loaded?` is true and then use `sort_by` otherwise use `order(created_at: :desc)` for exampleendend
If you have any suggestions on how to make this use-case simpler by changing panko - let me know, I am open to ideas :)
Hi, I would like to know how to add customize sorting logic in has_many association?
The text was updated successfully, but these errors were encountered: