Skip to content

Commit

Permalink
Fix schema type to be adjustable at runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Nov 18, 2024
1 parent 0f72703 commit c5dbf12
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 c5dbf12

Please sign in to comment.