I have one table(profiles) where each row has many rows in another
table(carriers).
If I write profile.carriers I get a collection containing all carriers
that belong to the current profile.
My question is: how do I sort the collection profile.carriers? I would
like to sort it on one of the columns (found in the table carriers). Can
I override some method in the carrier model or somewhere else that adds
an “order: => ‘columnname’” statement? Or is it possible to sort the
collection after it is filled with carriers?
With the former you always have the collection ordered by default.
The latter one orders the collection locally.
Note that find() in the latter case is not the regular
Enumerable#find. has_many brings an attribute that behaves quite
naturally like a regular collection, but find() is different is a
custom method.
– fxn
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.