Skip to content

Commit

Permalink
Merge pull request cakephp#7492 from cakephp/set-column-type
Browse files Browse the repository at this point in the history
Update docs for overriding column type.
  • Loading branch information
othercorey authored Aug 19, 2022
2 parents 889a4f4 + 8eccbbd commit 5e180af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
9 changes: 3 additions & 6 deletions en/orm/database-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -503,17 +503,14 @@ We then have two ways to use our datatype in our models.

Overwriting the reflected schema with our custom type will enable CakePHP's
database layer to automatically convert JSON data when creating queries. In your
Table's :ref:`_initializeSchema() method <saving-complex-types>` add the
Table's :ref:`initialize() method <saving-complex-types>` add the
following::

use Cake\Database\Schema\TableSchemaInterface;

class WidgetsTable extends Table
{
protected function _initializeSchema(TableSchemaInterface $schema): TableSchemaInterface
public function initialize(): void
{
$schema->setColumnType('widget_prefs', 'json');
return $schema;
$this->getSchema()->setColumnType('widget_prefs', 'json');
}
}

Expand Down
7 changes: 2 additions & 5 deletions en/orm/saving-data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1079,15 +1079,12 @@ column Types::
TypeFactory::map('json', 'Cake\Database\Type\JsonType');

// In src/Model/Table/UsersTable.php
use Cake\Database\Schema\TableSchemaInterface;

class UsersTable extends Table
{
protected function _initializeSchema(TableSchemaInterface $schema): TableSchemaInterface
public function initialize(): void
{
$schema->setColumnType('preferences', 'json');

return $schema;
$this->getSchema()->setColumnType('preferences', 'json');
}
}

Expand Down

0 comments on commit 5e180af

Please sign in to comment.