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

Deleting models while joined with another table with a where clause messes up the bindings. #18944

Closed
mihkelallorg opened this issue Apr 26, 2017 · 5 comments

Comments

@mihkelallorg
Copy link
Contributor

mihkelallorg commented Apr 26, 2017

  • Laravel Version: 5.1.46
  • PHP Version: 7.0.17
  • Database Driver & Version: MySQL 5.7.17 (Although I tackled the issue in SQLite also)

Description:

When trying to softdelete a model while joining with another table and using a where clause in the join function messes up the bindings.

Steps To Reproduce:

Model is using softdeletes, while the joined one is not.

Model::join('table', function($join) {
    $join->on('key', '=', 'otherKey')
         ->where('field', '=', 'foobar')
    })->delete();
}

Now the query, which is correct, is:

UPDATE model INNER JOIN table ON key = otherKey AND table.field = ? SET deleted_at = ?, updated_at = ? WHERE model.deleted_at IS NULL

But the bindings are messed up as the last one should be the first one actually:

"bindings" = [
    [0] => "2017-04-26 11:26:50",
    [1] => "2017-04-26 11:26:50",
    [2] => "foobar",
]
@mihkelallorg mihkelallorg changed the title Deleting models while joined with another and with an where clause messes up the bindings. Deleting models while joined with another table with a where clause messes up the bindings. May 12, 2017
@Dylan-DPC-zz
Copy link

5.1 is no longer supported. Can you check if issue persists on 5.5?

@abdumu
Copy link
Contributor

abdumu commented Dec 8, 2017

The mentioned problem is no longer valid - in my tests.
but there is a new problem - using same code above, this appear:

Integrity constraint violation: 1052 Column 'updated_at' in field list is ambiguous

MySQL : 5.7.19

@mfn
Copy link
Contributor

mfn commented Dec 16, 2017

@abdumu I believe what you're mentioning is #13909

However:

The mentioned problem is no longer valid - in my tests.
but there is a new problem - using same code above, this appear:

These two sentences contradict itself, don't they? How can we know the binding problem is really gone when the whole thing doesn't yet work? 😄

@abdumu
Copy link
Contributor

abdumu commented Dec 16, 2017

@mfn
The mentioned problem: the order of the bindings is not correct, but when I tested the order was correct. So, 'ambiguous' error has nothing to do with bindings problem.

How can we know the binding problem is really gone when the whole thing doesn't yet work?
You can debug and print the prepared Query. you know that right?

Shukran 🙂

@mfn
Copy link
Contributor

mfn commented Dec 16, 2017

Well, then this issue can be closed 😄 👍

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

5 participants