Weave 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

Doctrine Relations Laravel Package

midnightluke/doctrine-relations

Adds Laravel-style relationships to Doctrine entities, letting you define hasOne, hasMany, belongsTo, and belongsToMany associations with simple attributes and query them through an intuitive, Eloquent-like API.

View on GitHub
Deep Wiki
Context7

Getting Started

This is an unvetted micro-package (0 stars, 0 dependents, no ecosystem signals), so treat adoption as a code-review exercise before an install exercise.

  1. Read before you install. Open composer.json on the repo and check the constraints on php, illuminate/*, and doctrine/orm. Given the repo name and the Laravel context, the package almost certainly targets Doctrine ORM inside a Laravel app (via laravel-doctrine/orm or a hand-rolled EntityManager binding). If the constraints top out below your Laravel or Doctrine major version, stop there.
  2. Install pinned. Use composer require midnightluke/doctrine-relations only after confirming it resolves on Packagist; otherwise add it as a VCS repository and pin a commit hash ("midnightluke/doctrine-relations": "dev-main#<sha>"). Never float dev-main in a production app with no maintainer activity.
  3. Where to look first. src/ for the service provider and any traits/base classes, then the test suite (tests/) — it is the only reliable spec you have. The README is likely thin; the tests will tell you what the package actually does with associations.
  4. First use case. Take one existing entity with a OneToMany association and use the package to manage that collection — add/remove children, cascade persist, and read the inverse side — rather than rewriting your whole domain model. Compare the before/after against plain Doctrine cascade: ["persist"] plus your own addChild()/removeChild() methods; if the package is not clearly better, do not adopt it.

Implementation Patterns

  • Keep Doctrine mappings authoritative. Let the package be a helper layer over your entity metadata, not a second source of truth. Any annotation/attribute mapping should stay in the entity; helper methods should only orchestrate it.
  • Encapsulate collections in the entity. The usual win for a relations package is generated-style addX()/removeX() that keep both sides of a bidirectional association in sync. Wrap these behind domain methods ($order->addLine($line)) so controllers never touch raw collections.
  • Persist through the Unit of Work, not per-entity. In a Laravel controller or action, call your service, then a single $em->flush() inside a transaction ($em->wrapInTransaction(...) or DB::transaction around flush). Do not let a relations helper flush implicitly.
  • Service/repository layer. Bind the EntityManager (or a repository from $em->getRepository()) into a small service class; keep Eloquent and Doctrine code paths separate rather than mixing DB::table() with entity hydration.
  • Test harness. Use an in-memory SQLite or a dedicated test database with doctrine/orm schema tool (SchemaTool::createSchema) in a base test case, and reset the EntityManager between tests. Assert on both the owning and inverse sides after flush() + $em->clear() to prove the relation actually persisted.
  • Integration tip. If you already run laravel-doctrine/orm, register this package's provider after it and verify the EntityManager it resolves is the same instance (identity map mismatches are a classic failure here).

Gotchas and Tips

  • Support risk is the headline gotcha. Zero stars and zero dependents means no issue triage, no security disclosure path, and no guarantee of a PHP 8.4 or Doctrine ORM 3 fix. If you adopt it, vendor-fork it under your own namespace and own the maintenance.
  • Doctrine ORM 3 is a breaking line. ORM 3 replaced proxy-based lazy loading with lazy ghost objects; any relation helper that reaches into proxy internals or assumes Doctrine\Common\Persistence-era APIs will break. Check the ORM constraint in composer.json and run a full association test suite against your target ORM version before trusting it.
  • Identity map staleness in long-lived workers. Under Octane or queue workers, a shared EntityManager accumulates stale entities. Clear it per job/request ($em->clear()), and never cache entities across requests.
  • Lazy loading outside the request. Serializing entities to JSON (API resources) triggers lazy loads, and closed-EntityManager errors surface late. Prefer explicit JOIN/fetch-join DQL or $em->initialize() in the query layer, and map to DTOs before returning.
  • N+1 is easy to reintroduce. A convenient relations API often hides a getCollection() call in a loop. Log queries in dev, or assert query counts in a test, for any list endpoint that renders relations.
  • Cascade config vs database constraints. cascade: ["remove"] plus a real FK without ON DELETE CASCADE produces ordering bugs. Keep the database FK as the safety net and let the ORM cascade be the intent.
  • Extension points. Rather than patching the vendor tree in place, extend a base entity or decorate the repository in your own package, and keep the override in app/ so upgrades remain possible. Document every assumption about the package's API in a test — those tests are your upgrade contract.
  • Debugging. Doctrine\DBAL\Logging (or doctrine/dbal middleware in ORM 3) plus $em->getUnitOfWork()->getScheduledEntityInsertions() will tell you quickly whether the helper queued the relation or silently dropped it.
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.
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin
skyraptor/chatter
edlugz/sasapay
abbasudo/artisan-route