Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix schema type to be adjustable at runtime. #7955

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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