class User
has_many :posts
end
I want to render a json hash with the as_json method.
How would I order the posts in the code below by their updated_at
attribute without setting a default order on the association?
user.as_json(include: {posts: {include: :comments})
This will not be used as a request response and I'd like to avoid setting a default sorting on the association.
as_json
in the question you found? – Dishmanas_json
as well. Just try it out. – Cartilaginoususer.as_json(methods: : permalink)
in this method set your logic in a way, that will give you records withupdated_at
order. – Old