Skip to content

HasMany and HasOne support while updating or inserting models #1087

@brendt

Description

@brendt

Currently, it's prohibited to attach HasMany and HasOne relations directly via insert or update queries:

query(Book::class)
    ->insert(
        title: 'Timeline Taxi',

        // HasMany isn't allowed
        chapters: [
            Chapter::new(title: 'Chapter 01'),
        ],

        // HasOne isn't allowed
        isbn: new Isbn(''),
    )
    ->build();

Ideally we make it so that HasMany and HasOne relations get inserted/updated as well. The difficulty is that in their cases, they'll have to be inserted/updated after the original insert or update of the parent model. For that to work, we'd need a mechanism to run queries after another query (the parent query) has run.

In #1225, we added proper exceptions that prevent this from happening, but after 1.0 we could make it so that this works. However, in order to fix it properly, we need #1086

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions