sylius-labs/association-hydrator
Doctrine ORM association hydrator for Sylius apps, inspired by Ocramius’ hydration optimization technique. Helps efficiently load and hydrate entity associations to reduce queries and improve performance in read-heavy workflows.
doctrine/orm or laravel-doctrine/orm), making it adaptable to Laravel projects using Doctrine. Native Laravel Eloquent users may face higher integration friction.JOIN inefficiencies). Ideal for read-heavy workloads (e.g., product catalogs, inventory systems) where query optimization is critical.laravel-doctrine/orm) or fork Sylius’s integration layer.symfony/property-access, symfony/property-info, and symfony/serializer. Laravel’s DI container may require manual wiring.HydratorInterface and AssociationHydratorInterface. Custom hydrators can be implemented for domain-specific optimizations.EAGER, LAZY, or custom fetch plans).laravel-doctrine/orm for partial integration or evaluate hybrid approaches (e.g., Doctrine for read-heavy models, Eloquent for writes).sylius_association_hydrator.yaml). Misconfigurations may break lazy-loading or introduce memory leaks.EAGER strategies for critical paths, then optimize incrementally.doctrine/orm profiling tools). Hydrator-specific edge cases (e.g., circular references) may need custom tests.EventManager to log hydration events during testing.| Component | Compatibility | Workarounds |
|---|---|---|
| Laravel Framework | ❌ Native Eloquent: Low (requires Doctrine bridge) | Use laravel-doctrine/orm for partial integration. |
| Doctrine ORM | ✅ High (v2.10+) | Ensure doctrine/orm and doctrine/annotations are pinned to compatible versions. |
| Symfony Components | ✅ property-access, property-info, serializer are auto-installed via Composer. |
May need manual DI configuration in Laravel’s config/app.php. |
| Database | ✅ Works with PostgreSQL, MySQL, SQLite (Doctrine-supported DBAL). | Test with the target DB’s JOIN optimization (e.g., PostgreSQL’s EXPLAIN ANALYZE). |
| Caching Layer | ✅ Compatible with APCu, Redis, Doctrine Cache | Configure doctrine/orm cache drivers in config/packages/doctrine.yaml. |
SELECT * FROM products followed by N SELECT * FROM categories WHERE product_id = ?.laravel-doctrine/orm and configure in config/app.php:
'doctrine' => [
'orm' => [
'entity_managers' => [
'default' => [
'connection' => 'default',
'mappings' => [
'App\Entity' => __DIR__.'/../src/Entity',
],
],
],
],
],
doctrine/orm-tools for schema conversion).composer require sylius-labs/association-hydrator
config/packages/sylius_association_hydrator.yaml:
sylius_association_hydrator:
hydrators:
App\Entity\Product:
associations:
categories: EAGER
inventory: LAZY
AssociationHydrator).EntityManager::find() with hydrator-aware queries:
$product = $entityManager->getRepository(Product::class)
->createHydratedQueryBuilder()
->find($id);
loadClassMetadata and postLoad. Ensure no conflicts with existing listeners.// app/Providers/DoctrineServiceProvider.php
public function boot()
{
$this->app->make(HydratorExtension::class)->register();
}
doctrine/orm-functional-tests to validate hydration behavior.Product + Category).LAZY for non-critical associations).sylius_association_hydrator.yaml.How can I help you explore Laravel packages today?