Skip to content

Commit

Permalink
Merge pull request #7955 from cakephp/5.x-schema-type-fix
Browse files Browse the repository at this point in the history
Fix schema type to be adjustable at runtime.
  • Loading branch information
markstory authored Nov 18, 2024
2 parents 0f72703 + c5dbf12 commit a3a27b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 5 additions & 3 deletions en/orm/database-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,16 @@ 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:`getSchema() method <saving-complex-types>` add the
Table's :ref:`initialize() method <saving-complex-types>` add the
following::

class WidgetsTable extends Table
{
public function getSchema(): TableSchemaInterface
public function initialize(array $config): void
{
return parent::getSchema()->setColumnType('widget_prefs', 'json');
parent::initialize($config);

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

Expand Down
7 changes: 3 additions & 4 deletions en/orm/saving-data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1094,12 +1094,11 @@ column Types::

class UsersTable extends Table
{
public function getSchema(): TableSchemaInterface
public function initialize(array $config): void
{
$schema = parent::getSchema();
$schema->setColumnType('preferences', 'json');
parent::initialize($config);

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

Expand Down

0 comments on commit a3a27b1

Please sign in to comment.