Skip to content
Permalink
Browse files

Implemented a placeholder method "initialize" for tables, so that users

can easily configure their tables without overriding the constructor
  • Loading branch information...
lorenzo committed Oct 19, 2013
1 parent e888b23 commit 987b55f3257ca312f84a395df5f9288412746824
Showing with 25 additions and 4 deletions.
  1. +22 −1 Cake/ORM/Table.php
  2. +3 −3 Cake/Test/TestCase/ORM/TableTest.php
@@ -144,7 +144,7 @@ class Table {
* @param array config Lsit of options for this table
* @return void
*/
public function __construct($config = []) {
public function __construct(array $config = []) {
if (!empty($config['table'])) {
$this->table($config['table']);
}
@@ -172,6 +172,27 @@ public function __construct($config = []) {
$eventManager = $config['eventManager'];
}
$this->_eventManager = $eventManager ?: new EventManager();
$this->initialize($config);
}
/**
* This method is meant to be overridden by subclasses so that any initial setting
* up for associations, validation rules or any custom logic can be done.
*
* ### Example:
*
* {{{
* public function initialize(array $config) {
* $this->belongsTo('User');
* $this->belongsToMany('Tagging.Tag');
* $this->primaryKey('something_else');
* }
* }}}
*
* @param array $config Configuration options passed to the constructor
* @return void
*/
public function initialize(array $config) {
}
/**
@@ -517,7 +517,7 @@ public function testUpdateAllFailure() {
$table = $this->getMock(
'Cake\ORM\Table',
['_buildQuery'],
['table' => 'users', 'connection' => $this->connection]
[['table' => 'users', 'connection' => $this->connection]]
);
$query = $this->getMock('Cake\ORM\Query', ['executeStatement'], [$this->connection, null]);
$table->expects($this->once())
@@ -553,7 +553,7 @@ public function testDeleteAllFailure() {
$table = $this->getMock(
'Cake\ORM\Table',
['_buildQuery'],
['table' => 'users', 'connection' => $this->connection]
[['table' => 'users', 'connection' => $this->connection]]
);
$query = $this->getMock('Cake\ORM\Query', ['executeStatement'], [$this->connection, null]);
$table->expects($this->once())
@@ -571,7 +571,7 @@ public function testDeleteAllFailure() {
* @return void
*/
public function testFindApplyOptions() {
$table = $this->getMock('Cake\ORM\Table', ['_buildQuery'], ['table' => 'users']);
$table = $this->getMock('Cake\ORM\Table', ['_buildQuery'], [['table' => 'users']]);
$query = $this->getMock('Cake\ORM\Query', [], [$this->connection, $table]);
$table->expects($this->once())
->method('_buildQuery')

0 comments on commit 987b55f

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