Working with Relationships

Working with Relationships

Eloquent, leveraging the Active Record pattern, integrates relationship logic directly into model classes. Defining a relationship in Eloquent involves creating methods that return special relationship objects (HasOne, HasMany, BelongsTo, etc.). These methods encapsulate the SQL necessary to fetch related records, providing a fluent interface for querying and interacting with these relationships. Downside of this approach is that it can lead to bloated model classes and tight coupling between domain logic and database interactions.

Relationships in CycleORM are defined using annotations within the entity classes themselves. Instead of returning special relationship objects, CycleORM works directly with the related entities or collections of entities, providing a more direct representation of the domain model. This approach allows you to define relationships in a more declarative manner, keeping the domain logic separate from the persistence layer.

📚 Explore by Relationship Type