Welcome to the Cookbook

loading...

Model Databases and Datasources

Model

  • Model::del() and Model::remove() have been removed in favor of Model::delete(), which is now the canonical delete method.
  • Model::findAll, findCount, findNeighbours, removed.
  • Dynamic calling of setTablePrefix() has been removed. tableprefix should be with the $tablePrefix property, and any other custom construction behavior should be done in an overridden Model::__construct().
  • DboSource::query() now throws warnings for un-handled model methods, instead of trying to run them as queries. This means, people starting transactions improperly via the $this->Model->begin() syntax will need to update their code so that it accesses the model's DataSource object directly.
  • Missing validation methods will now trigger errors in development mode.
  • Missing behaviors will now trigger a cakeError.
  • Model::find(first) will no longer use the id property for default conditions if no conditions are supplied and id is not empty. Instead no conditions will be used
  • For Model::saveAll() the default value for option 'validate' is now 'first' instead of true

Datasources

  • DataSource::exists() has been refactored to be more consistent with non-database backed datasources. Previously, if you set var $useTable = false; var $useDbConfig = 'custom';, it was impossible for Model::exists() to return anything but false. This prevented custom datasources from using create() or update() correctly without some ugly hacks. If you have custom datasources that implement create(), update(), and read() (since Model::exists() will make a call to Model::find('count'), which is passed to DataSource::read()), make sure to re-run your unit tests on 1.3.

Databases

Most database configurations no longer support the 'connect' key (which has been deprecated since pre-1.2). Instead, set 'persistent' => true or false to determine whether or not a persistent database connection should be used

SQL log dumping

A commonly asked question is how can one disable or remove the SQL log dump at the bottom of the page?. In previous versions the HTML SQL log generation was buried inside DboSource. For 1.3 there is a new core element called sql_dump. DboSource no longer automatically outputs SQL logs. If you want to output SQL logs in 1.3, do the following:

<?php echo $this->element('sql_dump'); ?>
  1. <?php echo $this->element('sql_dump'); ?>

You can place this element anywhere in your layout or view. The sql_dump element will only generate output when Configure::read('debug') is equal to 2. You can of course customize or override this element in your app by creating app/views/elements/sql_dump.ctp.