Reputation: 345
Sorry about that title, wasn't too sure how I could word it.
In a sinatra web app using datamapper, I am returning an array of instances of a model (named Polls) like so:
user.new_polls.to_json(:relationships => {:options => {:methods => [:votes]}})
Each Poll has many Options, each option has many Votes.
How would I be able to return the options in its respective poll, in order of descending votes?
Thank you.
Upvotes: 1
Views: 53
Reputation: 6786
You can create a method in your Poll
model, called options_sorted_by_votes
(or something similar) and then use
user.new_polls.to_json(:relationships => {:options_sorted_by_votes => {:methods => [:votes]}})
Upvotes: 1