Skip to content

feat: create belongs-to-many related entities - #331

Merged
elpete merged 2 commits into
nextfrom
feat/84-belongs-to-many-create
Aug 24, 2026
Merged

feat: create belongs-to-many related entities#331
elpete merged 2 commits into
nextfrom
feat/84-belongs-to-many-create

Conversation

@elpete

@elpete elpete commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

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 one BelongsToMany.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.
  • Implicit 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:

  1. Creates and returns the loaded related entity.
  2. Attaches that entity to the parent.
  3. Passes the optional pivot attributes to the pivot support from feat: add belongs-to-many pivot models #353.

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 because create was 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

  • Focused stacked belongs-to-many suite: 12 passed, 0 failed, 0 errors
  • Full stacked suite on Lucee 6: 567 passed, 0 failed, 0 errors, 3 skipped
  • Formatter completed
  • git diff --check passed

Depends on #353.

@elpete
elpete force-pushed the feat/84-belongs-to-many-create branch 4 times, most recently from a277a23 to 6b23498 Compare August 24, 2026 18:52
@elpete

elpete commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator Author

Final validation after restacking on #353: all 27 CI checks are green. Once #353 merges, this PR reduces to the public-API regression test and the BelongsToMany.create() implementation.

@elpete
elpete force-pushed the feat/84-belongs-to-many-create branch from 6b23498 to d5d5b68 Compare August 24, 2026 19:27
@elpete
elpete merged commit a808fa6 into next Aug 24, 2026
27 checks passed
@elpete
elpete deleted the feat/84-belongs-to-many-create branch August 24, 2026 19:36
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

Successfully merging this pull request may close these issues.

1 participant