Data engine

Introduction

The TIP_Data_Engine class provides the abstract base class for all the data engine implementations of the TIP system.

The TIP_Data object

The data is accessed from a data source (a TIP_Data instance) that holds a reference to the data engine in its engine property and it is usually binded to a database table or a file throught its path property.

All the TIP_Content modules have a TIP_Data instance.

Moreover, the TIP_Data instance is a singleton class (based on the TIP_Type mechanism) that use the engine and the path property to build a uniquely id, so two modules can share the same data if they have the same data engine and path.

Remember also that, in TiP, all the data are based on a primary key access, that is there must be, for every data row, a field that identify this row. This is the primary key field, stored in the primary_key property. It defaults to 'id', but can be easely changed to any other valid field id.

How to join tables?

The TIP_Data object can also manage simple joined data tables. This is done by using the joins property of a TIP_Data instance in the following way:

$cfg = array(
    ...
    'blog'                          => array(
        'type'                      => array('module', 'content'),
        'data'                      => array(
            'joins'                 => array(
                'user'              => array(
                    'master'        => '_user',
                    'slave'         => 'id',
                    'fieldset'      => array('publicname', 'uri')
                )
            )
        )
    ),
    ...
);

This will join the `user`.`id` field to the `blog`.`_user` field (if not specified, the path property is set to the module id).

The only supported joins are 'LEFT JOIN' and are connected only using the '=' operator.

Also, in the fieldset property of the TIP_Data you can specify which fields you want to get from the binded table. If not specified, all the fields on the binded table will be included (and this can be quite dangerous because of field name collisions).

To avoid conflicts between the field name, you can specify aliases by using the keys on the fieldset array property.

Data engine was last modified by Nicola on Fri 15 May 2009 10:33:58 PM CEST
Hosted by BerliOS Developer Logo