[Solar-talk] sql_model auto-create
Paul M Jones
pmjones at solarphp.com
Sat Feb 10 10:54:45 PST 2007
Hi, devsmt,
> I wold like to understand how will be the workflow to define a new
> table...
The approach you defined should work just fine with the new
Solar_Sql_Model class. The code that loads the table column
definitions, Solar_Sql_Model::_loadTableCols(), works like this:
1. If the $_cache property is present, and column definitions exist
in the cache, load the definitions from the cache. If $_cache is not
present, or the column definitions were not in the cache, proceed to
step 2.
2. Connect to the database and look for the table corresponding to
this model. If it exists, load column definitions directly from the
database (and cache them if $_cache is present). If the table does
not exist, proceed to step 3.
3. If the $_table_cols property has values in it, use those to create
the table automatically. If creation fails at this point, throw an
exception. Otherwise, fetch the newly-created table columns from the
database (and cache them if $_cache is present).
So, you never need to define $_table_cols if you don't want to; you
can let the Model class examine the database, and you can specify a
$_cache object so that the Model class doesn't need to hit the
database for column definitions on every page load.
Hope this helps, please let me know if it does not.
--
Paul M. Jones <http://paul-m-jones.com>
Solar: Simple Object Library and Application Repository
for PHP5. <http://solarphp.com>
Join the Solar community wiki! <http://solarphp.org>
Savant: The simple, elegant, and powerful solution for
templates in PHP. <http://phpsavant.com>
More information about the solar-talk
mailing list