This class is used to specify the order of returned +Row+s. Whenever selecting rows you can use plain +Symbol+s for column names or the builtin classes for having the result automatically sorted asc ending, +desc+ending or case-insensitive with lower.

When executing SELECT on tables the method Base#compile_order is invoked, which compiles the order statement according to Table#default_order if defined. This can be overwritten with options[:order] set as parameter for the select method.

  class Feeds < Momomoto::Table
    default_order Momomoto.desc( :last_changed )
    #equals default_order :last_changed )

  newest_five_feeds = {}, { :limit => 5} )
    => Returns the five rows from Feeds with the newest column last_changed

Now, if you want to get all feeds sorted by column title instead of last_changed and also want to ignore case, do the following:

  feeds_by_title = {}, {:order => Momomoto::lower(:title)} )

This overwrites the default value for order.

You can also define multiple order statements at once, which are then joined together.

  class Feeds < Momomoto::Table
    default_order [Momomoto::desc(:last_changed), Momomoto::lower(:title)]
Classes and Modules
Class Momomoto::Order::Asc
Class Momomoto::Order::Desc
Class Momomoto::Order::Lower
[RW] fields Getter and setter methods for fields. fields are +Symbol+s representing the columns the Order class operates on.
Public Class methods
new( *fields )

Creates a new instance of Order and flattens the given parameter fields.

Usage:, [:url, :title])
# File lib/momomoto/order.rb, line 46
    def initialize( *fields )
      @fields = fields.flatten
Public Instance methods
to_sql( columns )

This method is used to build the SQL statement from the given columns and their class. This method is only invoked from Base#compile_order.

# File lib/momomoto/order.rb, line 53
    def to_sql( columns )
      sql = []
      fields.each do | field |
        if field.kind_of?( Momomoto::Order )
          sql << function( field.to_sql( columns ) )
          raise Momomoto::Error, "Unknown field #{field} in order" if not columns.keys.member?( field.to_sym )
          sql << function( field  )