Module RBatis::Repository::ClassMethods
In: lib/rbatis.rb

Methods

Public Instance methods

Returns a BooleanMapper, useful for resultmaps like this:

  resultmap :default,
    :username => ['userid', String],
    :email_offers => ['offersopt', boolean],

Creates a new instance of mapped_class.

inserts()

Alias for statements

Returns the mapped_class (specified with maps) or self if not specified.

Specify which class this Repository maps to.

Defines a named ResultMap which is a map from field name to mapping specification. For example:

  resultmap :default,
    :username => ['userid', String],
    :email => ['email', String],
    :first_name => ['firstname', String],
    :last_name => ['lastname', String],
    :address1 => ['addr1', String],
    :address2 => ['addr2', String],
    :city => ['city', String],
    :state => ['state', String],
    :zip => ['zip', String],
    :country => ['country', String],
    :phone => ['phone', String],
    :favourite_category_name => ['favcategory', String],
    :language_preference => ['langpref', String],
    :list_option => ['mylistopt', boolean],
    :banner_option => ['banneropt', boolean],
    :banner => RBatis::LazyAssociation.new(:to => Banner,
                                          :select => :find_by_favcategory,
                                          :key => :favourite_category_name),
    :favourite_category => RBatis::LazyAssociation.new(:to => Category,
                                                      :select => :find_by_name,
                                                      :key => :favourite_category_name)

Returns Hash of all resultmaps defined by resultmap.

selects()

Alias for statements

Instantiates the statement and puts it into statements also generates a class method with the same name that invokes the statement. For example:

  class Product < RBatis::Base
    statement :select_one, :find do |productid|
            ["SELECT * FROM product WHERE productid = ?", productid]
    end
  end

Can be invoked with:

  Product.select_one(id)

Note: This also needs a resultmap named +:default+:

statement_type is one of:

:select:Selects and maps multiple object (see Select)
:select_one:Selects and maps one object (see SelectOne)
:select_value:Selects a single value such as an integer or a string (see SelectValue)
:insert:Inserts new records into the database (see Insert)
:update:Updates the database (see Update)
:delete:Deletes records from the database (see Delete)
updates()

Alias for statements

[Validate]