Adding additional sorting attributes to array of records...then sorting!
Posted
by keruilin
on Stack Overflow
See other posts from Stack Overflow
or by keruilin
Published on 2010-06-17T02:48:25Z
Indexed on
2010/06/17
2:52 UTC
Read the original article
Hit count: 205
Let's say I run an ActiveRecord query and it returns 3 results, with a bunch of attributes.
I want to add 3 attributes to each record in the Array so I can do sorting at a code-level. These 3 include: num_comments, num_views, last_view.
- How do I add these attributes?
- How do I then sort the records, in order of precendence, by num_comments AND by num_views AND by last_view?
© Stack Overflow or respective owner