Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Different hasMany/SoftDelete behaviour between Laravel 8.x and 9.x #40400

Closed
nickurt opened this issue Jan 13, 2022 · 2 comments
Closed

Comments

@nickurt
Copy link
Contributor

nickurt commented Jan 13, 2022

  • Laravel Version: 8.79.0 vs 9.x (beta-1)
  • PHP Version: 8.0.13
  • Database Driver & Version: MySql 5.7

Description:

The MySql (5.7) Query is different between Laravel 8.79.0 and 9.x (beta-1), by 8.x it will include 'and posts.deleted_at is null' at the end of the query, while it's gone by 9.x.

class User extends Authenticatable
{
    //

    public function posts()
    {
        return $this->hasMany(Post::class);
    }
}

class Post extends Model
{
    use \Illuminate\Database\Eloquent\SoftDeletes;

    //
}


class ExampleTest extends TestCase
{
    public function test()
    {
        $user = new \App\Models\User;

        // Expected (Laravel 8) : 'select * from `posts` where `posts`.`user_id` is null and `posts`.`user_id` is not null and `posts`.`deleted_at` is null'
        // Actual (Laravel 9)   : 'select * from `posts` where `posts`.`user_id` is null and `posts`.`user_id` is not null'

        $this->assertSame('select * from `posts` where `posts`.`user_id` is null and `posts`.`user_id` is not null and `posts`.`deleted_at` is null', $user->posts()->toSql());
    }
}
inxilpro added a commit to inxilpro/laravel-framework-fork that referenced this issue Jan 14, 2022
@inxilpro
Copy link
Contributor

#40402 should fix this if merged!

@driesvints
Copy link
Member

The query builder changes have been reverted on 9.x so this should be resolved already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants