Skip to content

Laravel 11.19 breaks this package #16

Closed
@vesper8

Description

@vesper8

In Laravel 11.19 (https://github.com/laravel/framework/releases/tag/v11.19.0) this PR was added:

laravel/framework#52227

This causes this query:

        $snapshot = $this->snapshot
            ->newQuery()
            ->whereMorphedTo($this->snapshot->subject(), $this->model->getMorphClass())
            ->latest()
            ->first();

To result in this SQL:


select * from `model_snapshots` where `related_table`.`subject_type` = ? order by `created_at` desc

Instead of


select * from `model_snapshots` where `subject_type` = ? order by `created_at` desc

Basically it looks for subject_type on the related_table instead of on the model_snapshots table.

I'm not entirely sure why this is happening.. perhaps the whereMorphedTo method is the wrong method to use here?

Any chance you could fix this query so that it explicitly looks for subject_type to avoid this issue?

Something like this perhaps


$snapshot = $this->snapshot
    ->newQuery()
    ->where(function ($query) {
        $query->where('subject_type', $this->model->getMorphClass());
    })
    ->latest()
    ->first();

Many thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions