Skip to content
Permalink
Browse files

Adding a new method Table::_initializeSchema that users can override

  • Loading branch information...
lorenzo committed Jul 6, 2014
1 parent 669e5c9 commit 178c5870f242a1531088835ed0d92c9f1f5666ab
Showing with 29 additions and 3 deletions.
  1. +29 −3 src/ORM/Table.php
@@ -317,9 +317,11 @@ public function connection($conn = null) {
public function schema($schema = null) {
if ($schema === null) {
if ($this->_schema === null) {
$this->_schema = $this->connection()
->schemaCollection()
->describe($this->table());
$this->_schema = $this->_initializeSchema(
$this->connection()
->schemaCollection()
->describe($this->table())
);
}
return $this->_schema;
}
@@ -342,6 +344,30 @@ public function schema($schema = null) {
return $this->_schema = $schema;
}
/**
* Override this function in order to alter the schema used by this table.
* This function is only called after fetching the schema out of the database.
* If you wish to provide your own schema to this table without touching the
* database, you can override schema() or inject the definitions though that
* method.
*
* ### Example:
*
* {{{
* protected function _initializeSchema(\Cake\Database\Schema\Table $table) {
* $table->columnType('preferences', 'json');
* return $table;
* }
* }}}
*
* @api
* @param \Cake\Database\Schema\Table $table The table definition fetched from database.
* @return \Cake\Database\Schema\Table the altered schema
*/
protected function _initializeSchema(Schema $table) {
return $table;
}
/**
* Test to see if a Table has a specific field/column.
*

0 comments on commit 178c587

Please sign in to comment.
You can’t perform that action at this time.