Repository navigation
Fix BelongsToMany where_has with a query callback - #319
Merged
Merged
Conversation
query_where_exists passed the callback's QueryBuilder to where_in, so where_has/or_where_has with q.where(...) raised TypeError. Apply the callback to the related EXISTS query joined through the pivot, keeping id-list callbacks as a where_in on the related key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
BelongsToMany.query_where_existscalledwhere_in(other_owner_key, callback(query.select(...))). With a normal callback such aslambda q: q.where("name", "Widget")the callback returns aQueryBuilder, whichwhere_intries to iterate, soModel.where_has("products", cb)/or_where_hasraisedTypeError: 'QueryBuilder' object is not iterable.Fix
related_exists_query(builder)builds the related-table query joined through the pivot and correlated to the parent;query_hasandquery_where_existsshare it.query_where_existsapplies the callback to that related query inside the EXISTS (same as HasMany/BelongsTo). Callbacks that mutate in place and returnNonework too.related.other_owner_keywithwhere_in.No ADR (bug fix).
Tests
tests/masoniteorm/sqlite/relationships/test_belongs_to_many.py::TestBelongsToManyWhereHascovers where_has with no callback, a builder callback, a callback matching nothing, a callback returning None, an id-list callback, and or_where_has with and without a callback.get_with_count_queryhas the samewhere_in(callback(...))pattern but nothing in the builder calls it (there is nowith_count), so it is left as is.🤖 Generated with Claude Code