Skip to content

Improve BelongsTo, HasMany, and HasOne configuration #1078

@brendt

Description

@brendt

I've always been confused with what $inversePropertyName, $inverseClassName, and $localPropertyName mean within the context of ORM relations. What if we introduced a more human-readable approach?

final class Book
{
    #[BelongsTo('books.author_uuid = authors.uuid')]
    public ?Author $author = null;

    /** @var \App\Chapter[] */
    #[HasMany('chapters.book_uuid = books.uuid')]
    public array $chapters = [];
}

We can parse that string easily into the right parts. To me that makes much more sense than:

final class Book
{
    #[BelongsTo(localPropertyName: 'author_uuid', inversePropertyName: 'uuid')]
    public ?Author $author = null;

    /** @var \App\Chapter[] */
    #[HasMany(inversePropertyName: 'book_uuid', localPropertyName: 'uuid')]
    public array $chapters = [];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatabaseLiveBrent's filter for livestreams

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions