BasicModel::__construct |
( |
|
$con) | |
|
Create the table
- Returns
- boolean
Clear out any cached definition
BasicModel::createIfNeeded |
( |
|
$db_name) | |
|
Create structure only if it does not exist
- Parameters
-
$db_name | [string] database name |
- Returns
- [keyed array] db => database name struct => table/view name error => [int] error code error_msg => error details
Delete record from the database. Requires a uniqueness constraint. Assign those columns before calling delete().
- Returns
- boolean
Return information about the table/view this model deals with
BasicModel::find |
( |
|
$sort = '' , |
|
|
|
$reverse = false |
|
) |
| |
Find records that match this instance
- Parameters
-
$sort | array of columns to sort by |
- Returns
- an array of controller objects
BasicModel::generate |
( |
|
$filename) | |
|
Rewrite the given file to create accessor functions for all of its columns
BasicModel::getMeta |
( |
|
$type, |
|
|
|
$dbms |
|
) |
| |
|
protected |
Get database-specific type
- Parameters
-
$type | a "meta-type" with different underlying type depending on the DB |
$dbms | string DB name |
- Returns
- string
BasicModel::getModels |
( |
) | |
|
Experiment using lambdas. I was curious if I could do recursion without having a named function.
BasicModel::insertRecord |
( |
) | |
|
|
protected |
Helper. Build & execute insert query
- Returns
- SQL result object or boolean false
if the insert succeeded and the table contains an incrementing id column, that value will most likely be more useful than the result object
Populate instance with database values Requires a uniqueness constraint. Assign those columns before calling load().
- Returns
- boolean
BasicModel::loadHooks |
( |
) | |
|
|
protected |
Search available classes to load applicable hook objects into this instance
Compare existing table to definition Add any columns that are missing from the table structure Extra columns that are present in the table but not in the controlelr class are left as-is.
- Parameters
-
$db_name | name of the database containing the table |
$mode | the normalization mode. See above. |
- Returns
- number of columns added or False on failure
FannieDB only manages server connections. If normalize is called in lane mode, the calling function is responsible for initializing the connection.
Save current record. If a uniqueness constraint is defined it will INSERT or UPDATE appropriately.
- Returns
- [boolean] false on failure [SQL result] object or [int] ID on success
The only time save() will not return a result object on success is on an insert into a table containing an incrementing ID column. In most cases this is more useful. Databases typically start counting from 1 rather than 0 so it should still work to write: if ($model->save()) But it would be slightly safer to write: if ($model->save() !== false)
BasicModel::updateRecord |
( |
) | |
|
|
protected |
Helper. Build & execute update query
- Returns
- SQL result object or boolean false
BasicModel::validateOp |
( |
|
$operator) | |
|
|
protected |
Validate SQL binary operator
- Parameters
-
$operator | [string] operator |
- Returns
- [string] valid operator or [boolean] false
BasicModel::whichDB |
( |
|
$db_name) | |
|
Manually set which database contains this table. Normally this is autodetected by the constructor.
- Parameters
-
$db_name | [string] database name |
- Returns
- [boolean] success/failure
doesn't work
$this->fq_name = $this->connection->identifier_escape($db_name) . $this->connection->sep() . $this->connection->identifier_escape($this->name);
BasicModel::$cached_definition = false |
|
protected |
Cache table definition internally so that repeated calls to find(), save(), etc don't involve multiple extra queries checking table existence and structure every single time
BasicModel::$columns = array() |
|
protected |
Definition of columns. Keyed by column name. Values should be arrays with keys for:
- type (required)
- default (null if omitted)
- primary_key (optional, boolean)
- index (optional, boolean)
- not_null (optional, boolean)
- increment (optional, boolean)
- ignore_updates (optional, boolean)
- replaces (optional, string previous column name)
BasicModel::$connection = false |
|
protected |
BasicModel::$currently_normalizing_lane = false |
|
protected |
Status variable. Besides normalize() itself some hook functions may need to know if the current update is on the server vs on the lane.
BasicModel::$filters = array() |
|
protected |
Fully qualified table name Typically database.table Provided only if it can be detected If found, this name is more reliable since the connection is shared and outside code may change its state including the currently selected database.
If the database cannot be detected, $fq_name and $name will be identical.
BasicModel::$hooks = array() |
|
protected |
Array of hook objects associated with this table
BasicModel::$instance = array() |
|
protected |
List of column names => values
Initial value:= array(
'MONEY' => array('default'=>'DECIMAL(10,2)','mssql'=>'MONEY'),
'BIGINT UNSIGNED' => array('default'=>'BIGINT UNSIGNED', 'mssql'=>'BIGINT'),
)
Type transalations for different DB backends.
BasicModel::$normalize_lanes = false |
|
protected |
When updating server-side tables, apply the same updates to lane-side tables. Default is false.
BasicModel::$preferred_db = '' |
|
protected |
Name of preferred database
BasicModel::$record_changed = false |
|
protected |
boolean flag indicating at least one column record has been updated and the instances currently differs from the underlying database. Columns flagged as ignore_upates will not be considered a record change when their value is altered.
BasicModel::$unique = array() |
|
protected |
List of columns that should be unique per record. Only necessary if the table has no primary key.
const BasicModel::NORMALIZE_MODE_APPLY = 2 |
const BasicModel::NORMALIZE_MODE_CHECK = 1 |
check for potential changes
The documentation for this class was generated from the following file:
- fannie/classlib2.0/data/models/BasicModel.php