I'm new to Rails, so apologies if this is ignorant.
Suppose I have a User model, and a Friend model which is a many-to-many
User-to-User relationship. How might I retrieve an array of a given
user's friends, sorted by user name?
I'm retrieving an array of Friends from a Friend model, and using
belongs_to to access the User model. Does a find allow me sort by a
column on a linked table? I want to retrieve an array of friends and
not just users, as there are properties on the relationship that are
important to my Friend model.
I'm not even sure that this is correct place to do my sorting, but I
think the DB can handle sorting much faster than the application code.
Essentially, I want to do the equivalent of:
SELECT friends.*, users.*
FROM friends INNER JOIN users ON users.id = friends.user_id
ORDER BY users.name
Any guidance would be appreciated.