New Sado Version 1.1 released! Easily add ORM to your applications using our Sado Library

Sado Schema File

The Sado schema file "sado.schema.php" is a file that defines tables and fields for the Sado library. Also, the schema file controls table and field caching.

The schema file is located in: lib/Sado/sado.schema.php

Schema Caching

Schema caching can be turned on in the schema file. To turn on caching simply add the location of where a cache file should be saved (read/write permissions must be set for the location), here is an example:       '.schema' => array(
            'cache_file_path' => './cache/sado.schema.cache.php', // add cache file location here
      ),
The file needs to be saved as a PHP file. Now you should be able to cache your database by refreshing your app.

If you need to re-cache the database set the 'cache_force' flag to true:       '.schema' => array(
            'cache_file_path' => './cache/sado.schema.cache.php',
            'cache_force' => true, // force re-cache
      ),
After refreshing your app (which will re-cache the schema) set the flag back to false, otherwise Sado will continue to re-cache the database.

You can also have caching ignore specific tables in the database, for example you can set Sado schema caching to ignore these tables       '.schema' => array(
            'cache_file_path' => './cache/sado.schema.cache.php',
            'cache_force' => true,
            'cache_ignore' = > 'users, users_accounts, users_groups, users_types' // ignore 4 tables (they will not be cached)
      ),
And you can use wildcards for tables:             // following will ignore all tables that start with 'users' and will also ignore the table 'accounts'
            'cache_ignore' = > 'users*, accounts'
And you can also wildcards to ignore tables that end with a name, for example:             'cache_ignore' = > '*products' // ignores all tables that end with 'products'

Adding Tables and Fields

Manually defining tables and fields in the schema file is easy. To define a tables and fields do something like:             'table1' => array(
                  'key' => 'table1_id',
                  'fields' => 'field1, field2, field3'
            ),

            'table2' => array(
                  'key' => 'table2_id',
                  'fields' => 'field1, field2, field3'
            ),
Here is a more detailed look at table options:      'users' => array( // set the table name 'users'
            'key' => 'user_id', // define the primary key
            'fields' => 'fullname, email, is_active', // add the table fields
            'ignore' => 'date_created, date_modified', // these fields will be ignored (not cached when caching)
            'class' => 'User, User2', // this will add a relationship to classes (Sado will know these classes use this table/model)
      ),