Class FlexiRecord::BaseRecord
In: lib/flexirecord.rb
Parent: FlexiRecord::AbstractRecord

A record representing a row of a database table or query result.

Methods

Included Modules

MonitorMixin

Public Class methods

Adds two ManyToOneReferences and connects them to form a many-to-many relation between two other record classes. Please look at the FlexiRecordDemo module to see how this works.

Adds a ManyToOneReference to the class (by simply creating it). The first argument is the destination class, followed by arguments being passed to Reference.new.

Adds an OneToOneReference to the class (by simply creating it). The first argument is the destination class, followed by arguments being passed to Reference.new.

Adds a "shortcut" for a parameter to reader and loader functions.

Example: List.add_read_option :items, :by_name, ‘ORDER BY "name"’

This method is used on each Array of records being selected from the database via the ‘sql’ or ‘select’ method. It does nothing, but can be extended to automatically preload certain fields for example.

Autodetects the columns (and primary key columns) of the underlaying table, to be later retrieved by the ‘columns’ and the ‘primary_columns’ methods.

Returns an array of columns (String‘s) of the underlaying table. The columns may be autodetected (and cached) at the first call of this method.

Returns the connection pool being used for this class in general.

Sets the connection pool to use for this class in general.

Executes the given SQL command with optional arguments on the database being used to store objects of this class. Returns nil.

Executes the given SQL query with optional arguments on the database being used to store objects of this class. Returns an array of BaseRecord‘s (but NOT sub-classes of BaseRecord) containing the data of all rows of the query result.

Executes the given SQL query with optional arguments on the database being used to store objects of this class. Returns an array of BaseRecord‘s (but NOT sub-classes of BaseRecord) containing the data of the first row of the query result.

Returns the isolation_level of a transaction in progress on the connection used for accessing the table of this class.

Returns the loader function (a Proc object) for a certain attribute.

Locks the table used to store objects of this class. Calling this command only makes sense, if a transaction is in progress.

Creates a new record object with the given keys and values in the ‘data’ hash. If ‘saved’ is true, it is considered to be existent in the database already, if ‘saved’ is false (default), it is considered to be a new object, which has not been saved.

Modifies a parameter array by replacing "shortcut" symbols being defined by add_read_option. Returns the parameter array.

Returns an array of columns (String‘s) being part of the primary key of the underlaying table. (This will be in most cases an Array with one entry.) The columns may be autodetected (and cached) at the first call of this method.

Returns the value of a "shortcut" for a parameter to reader and loader functions.

Returns the reader function (a Proc object) for a certain attribute.

Returns an array containing all attributes having a reader Proc stored in the class.

Returns the database schema name of this class (or of it‘s superclass, if it has no own schema name)

Returns the database schema name, even if no schema is set (in this case "public" is returned).

Sets the database schema name for this class.

Wrapper for the ‘sql’ method including already a part of the SQL select command. Please see the source code to understand how this method works.

Same as ‘select’, but returns only the first member of the Array, or nil.

Executes an SQL query, selecting rows matching a given set of keys and values, optionally appending a given SQL snippet with parameters. Returns an Array of records.

Sets a given block to be the "loader function" for a particular attribute. Loader functions are invoked, when you try to read an uncached value of the given attribute of a record, or when you preload data for a whole Array of records. Two arguments are passed to the block. The first is an Array of records, whose data is to be loaded, the second is an Array of arguments passed to the method used for accessing the value. The block has to evaluate to an Array of records, which can be used for more than one level deep preloads.

Sets a given block to be the "reader function" for a particlular attribute. A reader function is invoked, when you try to read a value of the given attribute of a record. Two arguments are passed to the block. The first is the record, whose data is to be read, the second is an Array of arguments passed to the method used for reading the value. The block has to evaluate to the value which should be read.

Sets a given block to be the "setter function" for a particular attribute. The setter function is invoked, when you set the value of the given attribute of a record. Two arguments are passed to the block. The first is the record, whose data is to be changed, the second is the new value to be written into the field.

Returns the setter function (a Proc object) for a certain attribute.

Executes the given SQL query with optional arguments on the database being used to store objects of this class. Returns an array of objects of the class this method is used on (containing the data of all rows of the query result).

Executes the given SQL query with optional arguments on the database being used to store objects of this class. Returns a single object of the class this method is used on (containing the data of the first row of the query result.)

Returns an SQL snippet including the quoted schema and table name.

Returns the table name of this class (or of it‘s superclass, if it has no own table name)

Returns the table name, or raises an error, if no name is found.

Sets the database table name for this class. This must only be used on sub-classes of BaseRecord, and never on BaseRecord itself.

Returns the ConnectionPool being used for the current thread, if an explicit pool was set for the current thread.

Sets the ConnectionPool to use for this class in the current thread.

Wraps the given block in a transaction of the database being used to store objects of this class. See FlexiRecord::Connection#transaction for details of the command.

Returns true, if a transaction is in progress on the connection used for accessing the table of this class.

Calls the given block with a Connection object to the database being used to store objects of this class.

Public Instance methods

Reads a value (whose key can consist of multiple fields) from the internal cache. The first argument is by convention usually a name of a column as String(!), but NOT as a Symbol.

Writes a value to the internal cache. The first argument is by convention usually a name of a column as String(!), but NOT as a Symbol.

Deletes an entry from the internal cache, and returns it‘s value.

Destroys the record in the database, by executing a DELETE command.

Duplicates a record, including it‘s internal state.

Returns true, if the internal cache has stored the specified entry, otherwise false.

Returns a string representation of the record for debugging purposes.

Provides easy access to the fields of the record.

Reads an attribute. If there is a dynamic reader, this reader is used, otherwise an existent assigned loader function is invoked or the internal cache will give a result. If there is no data for the attribute with the given name, then nil will be returned.

Reloads the record from the database. It can not be used on records, which have not been saved to the database yet.

Replaces the internal state with the state of a backup. This method is needed for transaction rollbacks.

Saves the record in the database, either by INSERT‘ing or UPDATE‘ing it.

Returns true, if the record has been saved in database once, otherwise false.

Sets an attribute. If there is a dynamic setter, this setter is used, otherwise the value get‘s written in the internal cache.

Alias for the inspect method.

Wraps the given block in a transaction of the database being used to store the object. See FlexiRecord::Connection#transaction for details of the command. This object is automatically passed to the FlexiRecord::Connection#transaction method, to rollback changes, in case an Error is raised.

Rewrites several attributes given by the keys and values in the ‘data’ hash. Note: A SQL UPDATE command is not executed before ‘save’ is called, this method just updates the ruby object. Returns self.

Returns an array of strings of the columns in the backend database, which have either values in the internal cache, or which have a dynamic reader function.

Protected Instance methods

Helper method for dup and replace. Do not use directly.

Helper method for dup and replace. Do not use directly.

Private Instance methods

Saves a copy of the values of the primary key in the @old_primary_key Array.

[Validate]