Repository navigation
Fix callback conditions in present() ifExists() being dropped or rewritten and add whereNotIn() to the Entity builder - #355
Merged
Conversation
…itten and add whereNotIn() to the Entity builder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Checklist
whereNotIn()/orWhereNotIn())Description
Two small, related changes to the Entity ORM query builder.
1. Fix: conditions inside
present()callbacks lose their meaningpresent(),orPresent(),ifExists()and their nested forms (articles.notes) build anEXISTSsubquery. The conditions a callback adds were not compiled; they were copied one by one into hand-written SQL (addCallbackConditions()and a similar loop inInteractsWithNestedRelations). That loop:type(nestedwhere(fn ...)groups,whereRaw()),ANDand ignored the stored boolean, soorWhere()becameAND,whereNull()/whereNotNull()(its NULL branch only handled=and!=),The wrong result is silent, and it usually returns more rows than it should:
Fix. The callback's query is now compiled with the regular WHERE compiler (the same one the main query uses):
OR, nested groups, raw conditions and NULL checks keep their meaning.EXISTScondition instead of being inlined.withTrashed()/onlyTrashed()inside a callback keep working.whereLinked()takes a single condition rather than a callback, so it was not affected.2. Feature:
whereNotIn()/orWhereNotIn()The Entity builder had
whereIn()/orWhereIn()but noNOT INcounterpart. CallingwhereNotIn()fell through to the dynamicwherehandler and generated invalid SQL (not_in body ?).1=1), the inverse of the empty-INcase (1=0).join().NOT INis handled by the WHERE compiler, thewhereLinked()clause builder, the legacy nested-binding path andDebuggable.count, aggregates, bulkupdate/delete, nested groups andpresent()callbacks.Tests
tests/Model/RelationExists/(13 tests x 3 drivers):OR, nested groups, raw conditions, NULL checks, the remaining operators, quoted / injection-style values, binding order around the callback,count(), many-to-many, nested relations,ifExists(), and the interplay with soft deleted rows.tests/Model/Query/EntityModelQueryBehavior.php: sixwhereNotIn/orWhereNotIntests next totestWhereIn(empty list, key gaps,OR, binding order, nested group,count/sum/ bulkupdate, join qualification).Checklist