Class ActiveRecord::Base
In: kirbybase_adapter.rb
Parent: Object

INSTANCE METHODS: Override SQL based methods in ActiveRecord::Base Instance methods: everything invoked from records instances, e.g. book = Book.find(:first); book.destroy

Methods

Constants

SQL_FRAGMENT_TRANSLATIONS = [ [/1\s*=\s*1/, 'true'], ['rec.', ''], ['==', '='], [/(\w+)\s*=\s*/, 'rec.\1 == '], [/(\w+)\s*<>\s*?/, 'rec.\1 !='], [/(\w+)\s*<\s*?/, 'rec.\1 <'], [/(\w+)\s*>\s*?/, 'rec.\1 >'], [/(\w+)\s*IS\s+NOT\s*?/, 'rec.\1 !='], [/(\w+)\s*IS\s*?/, 'rec.\1 =='], [/(\w+)\s+IN\s+/, 'rec.\1.in'], [/\.id(\W)/i, '.recno\1'], ['<>', '!='], [/\bNULL\b/i, 'nil'], [/\bAND\b/i, 'and'], [/\bOR\b/i, 'or'], ["'%s'", '?'], ['%d', '?'], [/:\w+/, '?'], [/\bid\b/i, 'rec.recno'], ]   TODO: handle LIKE

External Aliases

serialize -> __before_ackbar_serialize

Public Class methods

NOT SUPPORTED!!!

Builds the :conditions block from various forms of input.

  • Procs are passed as is
  • Arrays are assumed to be in the format of [‘name = ?’, ‘Assaph’]
  • Fragment String are translated to code Full SQL statements will raise an error
  • No parameters will assume a true for all records

One of the main methods: Assembles the :conditions block from the options argument (See build_conditions_block for actual translation). Then adds the scope and inheritance-type conditions (if present).

NOT SUPPORTED!!!

Override of AR::Base SQL construction to build a conditions block. Used only by AR::Base#method_missing to support dynamic finders (e.g. find_by_name).

May also be called with a block, e.g.:

  Book.count {|rec| rec.author_id == @author.id}

NOT SUPPORTED !!!

The KirbyBase object

Override of AR::Base that was using raw SQL

Deletes the selected rows from the DB.

Deletes the matching rows from the table. If no conditions are specified, will clear the whole table.

This methods differs in the API from ActiveRecord::Base#find! The changed options are:

  • :conditions this should be a block for selecting the records
  • :order this should be the symbol of the field name
  • :include: Names associations that should be loaded alongside using KirbyBase Lookup fields

The following work as before:

  • :offset: An integer determining the offset from where the rows should be fetched. So at 5, it would skip the first 4 rows.
  • :readonly: Mark the returned records read-only so they cannot be saved or updated.
  • :limit: Max numer of records returned
  • :select: Field names from the table. Not as useful, as joins are irrelevant

The following are not supported (silently ignored);

  • :joins: An SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id".

As a more Kirby-ish way, you can also pass a block to find that will be used to select the matching records. It’s a shortcut to :conditions.

NOT SUPPORTED !!!

Override of AR::Base that was using raw SQL

Attempt to parse parameters in the format of [‘name = ? AND value = ?’, some_name, 1] in the :conditions clause

Attempt to parse parameters in the format of [‘name = ?’, some_name] for updates

Attempt to parse parameters in the format of ‘name = "Some Name"’ for updates

Serializing a column will cause it to change the column type to :YAML in the database.

The KBTable object for this AR model object

Translates SQL fragments to a code string. This code string can then be used to construct a code block for KirbyBase. Relies on the SQL_FRAGMENT_TRANSLATIONS series of transformations. Will also remove table names (e.g. people.name) so not safe to use for joins.

For handling the table inheritance column.

Updates the matching rows from the table. If no conditions are specified, will update all rows in the table.

Public Instance methods

translates the Active-Record instance attributes to a input hash for KirbyBase to be used in insert or update

Creates a new record with values matching those of the instance attributes.

KirbyBase DB Object

Deletes the matching row for this object

Table for the AR Model class for this record

Updates the associated record with values matching those of the instance attributes. Will also check for a lock (See ActiveRecord::Locking.

update_without_callbacks()

Alias for update_with_lock

Updates the associated record with values matching those of the instance attributes.

[Validate]