feat: create belongs-to-many related entities - #331
Open
elpete wants to merge 2 commits into
Open
Conversation
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
The two relationship types in this request have different semantics.
belongsToMany.create: 9/10. The parent, related entity, and single pivot row are unambiguous, so Quick should support this.hasManyThrough.create: 3/10. A parent can have several intermediate entities (and an arbitrarily deep chain), so Quick cannot safely infer which intermediate row should own the new terminal entity.Reasons for
belongsToMany.create()match developer expectations.attach(), which now also accepts optional pivot attributes.Reasons against
attach.hasManyThrough.createwould be ambiguous and could associate data with the wrong intermediate entity.Implementation
var tag = post.tags().create( { name : "testing" }, { context : "created through relationship" } );The method creates and returns the loaded related entity, then attaches it. Pivot key values are generated by Quick and cannot be overwritten by the additional pivot attributes.
Test-first evidence
Before implementation, the public
post.tags().create(...)call fell through the relationship builder and errored withMethod does not exist on QueryBuilder [create].The integration test now verifies the returned
Tag, persisted target row, relationship association, and additional pivot-field value.Validation
git diff --checkpassedqb@14.0.0-beta.3