oro/platform-serialised-fields
Installation:
composer require oro/entity-serialized-fields-bundle
Ensure Oro\Bundle\EntityExtendBundle\OroEntityExtendBundle is also installed (this package depends on it).
Enable Bundle:
Add to config/bundles.php:
Oro\Bundle\EntityExtendBundle\OroEntityExtendBundle::class => ['all' => true],
Oro\EntitySerializedFieldsBundle\OroEntitySerializedFieldsBundle::class => ['all' => true],
First Use Case:
Extend an entity (e.g., Product) with a serialized field:
php bin/console oro:entity-extend:create-field --entity=Product --field-name=customAttributes --type=serialized
This generates a migration and adds a customAttributes column (e.g., product_custom_attributes) to store JSON/array data.
Accessing Data:
$product = $entityManager->getRepository(Product::class)->find(1);
$customData = $product->getCustomAttributes(); // Returns array/JSON
$product->setCustomAttributes(['key' => 'value']);
Dynamic Field Management:
config, metadata) without schema migrations.// In a form type
$builder->add('customAttributes', SerializedFieldType::class, [
'label' => 'Custom Attributes',
'required' => false,
]);
Data Validation:
Assert\Json, Assert\Type).use Symfony\Component\Validator\Constraints as Assert;
/**
* @Assert\Type("array")
* @Assert\Json()
*/
private $customAttributes;
Querying Serialized Data:
WHERE customAttributes->>'$.key' = 'value').Integration with OroPlatform:
# oro/platform/src/Oro/Bundle/UIBundle/Resources/config/oro/grid.yml
ProductGrid:
columns:
customAttributes:
type: twig
template: OroUIBundle:Grid:FieldValue.html.twig
frontend_options:
field: customAttributes
Migration Strategy:
oro:entity-extend:create-field for new fields.$product->setCustomAttributes(json_decode($oldData, true));
$entityManager->flush();
Performance:
jsonb (PostgreSQL) or JSON (MySQL 5.7+) for better indexing/querying.Schema Locks:
Data Corruption:
json_last_error() in PHP to debug malformed data.Doctrine Proxy Issues:
@ORM\LazyGroup or fetch data eagerly:$query->setHint(QueryHint::HINT_REFRESH, 'Product');
OroPlatform-Specific:
serialized) may conflict with other bundles.DQL Errors:
Use JSON_EXTRACT() (MySQL) or ->> (PostgreSQL) for partial queries. Example:
SELECT p FROM Product p WHERE JSON_EXTRACT(p.customAttributes, '$.key') = 'value'
Field Not Found: Verify the field was created via:
php bin/console oro:entity-extend:list-fields Product
Serialization Failures:
Check for circular references or non-serializable objects (e.g., Doctrine proxies). Use json_encode($data, JSON_THROW_ON_ERROR).
Custom Serialization: Override the serializer via dependency injection:
services:
app.serialized_field_serializer:
class: App\Serializer\CustomSerializer
tags:
- { name: oro_entity_extend.serializer, type: serialized }
Field Type Extensions:
Extend the SerializedFieldType in Symfony forms to add custom widgets or validation.
Event Listeners:
Hook into oro_entity_extend.field.create or oro_entity_extend.field.update to log changes or trigger actions.
Default Storage Engine:
The bundle uses Doctrine’s json type by default. For MySQL < 5.7, configure a custom type:
oro_entity_extend:
field_types:
serialized:
type: string
length: 65535
Legacy Data: If migrating from a non-serialized field, ensure the new column is nullable during the transition.
How can I help you explore Laravel packages today?