Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Association Hydrator

Association Hydrator Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Doctrine ORM hydration performance optimization made easier.

Frequently asked questions about Association Hydrator
Can I use SyliusLabs/AssociationHydrator in a Laravel project without full Doctrine ORM migration?
No, this package requires Doctrine ORM (v2.10+) and won’t work natively with Eloquent. You’d need to integrate a Doctrine bridge like `laravel-doctrine/orm` for partial compatibility, targeting only read-heavy models where hydration optimization is critical.
What’s the best way to profile performance gains before adopting this package?
Use Doctrine’s built-in profiling tools (e.g., `doctrine/orm` with `PROFILING` mode) or Laravel’s query logging (`DB::enableQueryLog()`) to measure N+1 queries. Compare baseline metrics before and after applying hydrator configurations to validate ROI.
How do I configure eager-loading strategies for specific entity associations?
Define hydration strategies in a YAML/XML file (e.g., `sylius_association_hydrator.yaml`) using keys like `EAGER`, `LAZY`, or custom fetch plans. For example, specify `sylius.product.variants: EAGER` to preload variants when fetching products. Refer to the Sylius docs for syntax details.
Will this package work with Laravel’s caching (Redis, APCu) for further optimization?
Yes, but caching should target the *results* of hydration, not the hydrator itself. Configure Doctrine’s cache drivers (e.g., `redis://`) in your `config/packages/doctrine.yaml` to cache metadata or query results, complementing the hydrator’s query reduction.
Are there alternatives to this package for Eloquent users looking to optimize hydration?
For Eloquent, consider `spatie/laravel-query-builder` for eager-loading optimizations or `laravel-model-caching` for caching hydrated models. However, these won’t match Doctrine’s granular hydration control. If you’re open to Doctrine, `ocramius/doctrine-hydration` is a lighter-weight alternative.
How does this handle circular references in entity graphs (e.g., Product ↔ Category ↔ Product)?
The package supports circular references via Symfony’s `property-access` component, but you may need to define custom hydrators or use annotations (e.g., `@Hydrate`) to explicitly manage these cases. Test thoroughly with your entity graphs to avoid infinite loops or memory issues.
What Laravel versions and Doctrine ORM versions are officially supported?
The package is designed for Sylius 1.12+, which uses Doctrine ORM v2.10+. For Laravel, ensure you’re using `laravel-doctrine/orm` v3.x+ and pin `doctrine/orm` to a compatible version (e.g., `^2.10`). Check the SyliusLabs repo for the latest compatibility matrix.
Can I use this package alongside Laravel’s native caching (e.g., caching entire entities)?
Yes, but prioritize hydration optimizations for frequently accessed, complex associations. Cache *hydrated* entities (e.g., with `Cache::remember`) rather than relying solely on the hydrator. Combine both strategies for maximum efficiency in read-heavy workflows.
How do I implement custom hydrators for domain-specific optimizations?
Extend the `AssociationHydratorInterface` and implement logic for your use case (e.g., filtering associations or using custom fetch plans). Register your hydrator in Symfony’s DI container (or Laravel’s `config/app.php`) and reference it in your YAML configuration under a unique key.
What are the risks of misconfiguring hydration strategies (e.g., over-eager loading)?
Over-eager loading can bloat memory usage or trigger unnecessary JOINs, degrading performance. Start with conservative `LAZY` strategies for non-critical paths, then optimize incrementally using Doctrine’s profiling tools. Monitor memory spikes in production with tools like Blackfire.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime