Class Lafcadio::Query
In: lafcadio/query.rb
Parent: Object

Methods

Attributes

condition  [R] 
domain_class  [R] 
include  [R] 
limit  [R] 
order_by  [R] 
order_by_order  [RW] 

Public Class methods

Infers a query from a block. The first required argument is the domain class. Other optional arguments should be passed in hash form:

:order_by
An array of fields to order the results by.
:order_by_order
Possible values are :asc or :desc. Defaults to :desc.
  qry = Query.infer( User ) { |u| u.lname.equals( 'Hwang' ) }
  qry.to_sql # => "select * from users where users.lname = 'Hwang'"
  qry = Query.infer(
    SKU,
    :order_by => [ :standardPrice, :salePrice ],
    :order_by_order => :desc
  ) { |s| s.sku.nil? }
  qry.to_sql # => "select * from skus where skus.sku is null order by
                   standardPrice, salePrice desc"

Public Instance methods

Returns a new query representing the condition of the current query and the new inferred query.

  qry = Query.infer( User ) { |u| u.lname.equals( 'Hwang' ) }
  qry.to_sql # => "select * from users where users.lname = 'Hwang'"
  qry = qry.and { |u| u.fname.equals( 'Francis' ) }
  qry.to_sql # => "select * from users where (users.lname = 'Hwang' and
                   users.fname = 'Francis')"

Returns a new query representing the condition of the current query and the new inferred query.

  qry = Query.infer( User ) { |u| u.lname.equals( 'Hwang' ) }
  qry.to_sql # => "select * from users where users.lname = 'Hwang'"
  qry = qry.or { |u| u.fname.equals( 'Francis' ) }
  qry.to_sql # => "select * from users where (users.lname = 'Hwang' or
                   users.fname = 'Francis')"

[Validate]