feat: create belongs-to-many related entities - #331
Merged
Conversation
elpete
force-pushed
the
feat/84-belongs-to-many-create
branch
4 times, most recently
from
August 24, 2026 18:52
a277a23 to
6b23498
Compare
Collaborator
Author
elpete
force-pushed
the
feat/84-belongs-to-many-create
branch
from
August 24, 2026 19:27
6b23498 to
d5d5b68
Compare
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.
Closes #84
Review
This is the second PR in the belongs-to-many stack and now contains only relationship
create()support. Pivot models, pivot attributes, constraints, timestamps, and persistence are implemented separately in #353.Both PRs target
next. Until #353 merges, GitHub will show its commits in this PR as the shared foundation. After #353 lands, this PR's production diff is oneBelongsToMany.create()method.The two relationship types requested by the issue have different semantics:
belongsToMany.create: 9/10. The parent, related entity, and one pivot row are unambiguous.hasManyThrough.create: 3/10. A parent can have several intermediate entities or an arbitrarily deep chain, so Quick cannot infer which intermediate row should own the terminal entity.This PR implements only the unambiguous belongs-to-many case.
Implementation
var tag = post.tags().create( { name : "testing" }, { context : "created through relationship" } );The method:
The related insert and pivot insert remain separate operations. Quick does not imply aggregate or unit-of-work persistence; callers requiring atomicity should provide their transaction boundary.
Test-first evidence
Before implementation, the public
post.tagsWithPivot().create(...)call errored becausecreatewas forwarded to qb and did not exist. The test now verifies the returned entity and reloads the relationship through Quick's public API to verify both the association and pivot values.Validation
git diff --checkpassedDepends on #353.