Topics

Models

The basic data structure of a module which includes the database table Definition and the code to manage the data Model.  The models are stored in the module's 'models' subfolder and the definitions are stored in the module's 'definitions' sub folder.  Many modules contain multiple Definitions and Models.

The Definition file is only used when creating or updating the table definitions (install/update tables).  It returns an array of table field names and types.  There must be a Definition file for every table in the Exponent database.  Model properties correspond to the database table's fields and are determined at runtime from the database, not the definition file.  Therefore it's important to 'Update Tables' after a model definition has changed.

The Model file is typically an extension of the expRecord class and therefore inherits most of the infrastructure for creating, updating and deleting a record without requiring additional code, except where needed.  Some Definitions do not require a Model. especially if they are for an 'associated' table.

In a pure sense, a module Model should be the only piece of the module interacting with the gobal $db database object.  Meaning, there should never be a reference to the $db object in either the module controller nor the view.  This is because the Model is the abstract interpretation of the database for the controller.  While this isn't always true, it is possible to move any $db call within a controller into the model by creating a new model property.

Loading Help