| 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
| 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 |
| serialize | -> | __before_ackbar_serialize |
Builds the :conditions block from various forms of input.
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).
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).
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:
The following work as before:
The following are not supported (silently ignored);
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.
Attempt to parse parameters in the format of [‘name = ? AND value = ?’, some_name, 1] in the :conditions clause
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.
Updates the matching rows from the table. If no conditions are specified, will update all rows in the table.
translates the Active-Record instance attributes to a input hash for KirbyBase to be used in insert or update
Updates the associated record with values matching those of the instance attributes. Will also check for a lock (See ActiveRecord::Locking.