After using the PradeepKumar idea, I found the following solution to work
Assuming a class Blockthat has an attribute block_typeand a container class (like a page), you can have something like this:
class Page
...
has_many :blocks do
def ordered_by_type
self.sort_by(&:block_type)
end
end
...
end
Then when you call
page.blocks.ordered_by_type
you get what you want - defined by Proc. Obviously, Proc can be much more complicated and does not work in an SQL call, but after the result set has been compiled.
UPDATE:
I am re-reading this post and my answer after a lot of time, and I wonder if you can do something as easy as the other method that you basically suggested to yourself in this post.
, Game, ordered_texts
def ordered_texts
texts.in_game_order(self)
end
? Game?