arthem/object-reference-bundle
Actor, Director, Producer) in a single column via closures, simplifying schema design for polymorphic associations. Avoids the need for discriminator columns or complex SingleTableInheritance/ClassTableInheritance setups.ManyToOne with targetEntity dynamic loading) when performance or simplicity is prioritized over strict ORM conventions.User, Organization, or AIModel.createdBy could be a User or ServiceAccount).Adopt When:
SingleTableInheritance or ClassTableInheritance).actorId and actorType fields to be declared, even if unused).Look Elsewhere When:
Story entities with their Actor loaded in one query). This package’s closure-based approach may not optimize for this.targetEntity in ManyToOne) and don’t mind the overhead of discriminator columns."This package lets us store relationships to multiple entity types (e.g., users, services, or AI agents) in a single column—without complex database schemas or performance hits. For example, a ‘Story’ could be authored by any type of entity, and we’d only need one column to track it. This simplifies our content platform’s flexibility while keeping the database clean. It’s a lightweight ‘buy’ vs. building a custom solution, with minimal risk since it’s MIT-licensed and integrates seamlessly with our existing Symfony/Laravel stack."
Key Benefits:
*"The ObjectReferenceBundle solves a common pain point: storing polymorphic references (e.g., Actor could be a User, Organization, or AIModel) in a single column using Doctrine ORM. Here’s how it works:
getActor() is called. The actual ID and type are stored in separate fields (actorId, actorType).JOIN).*Id and *Type fields, even if unused.Recommendation: Pilot this for a non-critical polymorphic relationship (e.g., ‘createdBy’ in audit logs) to validate performance and ease of use before wider adoption. If it works, it could replace ad-hoc JSON columns or complex inheritance setups."*
Alternatives Considered:
How can I help you explore Laravel packages today?