Skip to content

Commit

Permalink
Adding a new method Table::_initializeSchema that users can override
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jul 6, 2014
1 parent 669e5c9 commit 178c587
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/ORM/Table.php
Expand Up @@ -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;
}
Expand All @@ -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.
*
Expand Down

0 comments on commit 178c587

Please sign in to comment.