feat: add belongs-to-many pivot models - #353
Merged
Merged
Conversation
Collaborator
Author
|
CI follow-up: the first matrix exposed three portability details in the new pivot hydration path—Adobe property declaration ordering, Adobe full-null handling for an unset custom pivot mapping, and BoxLang representing the declared-but-unset mapping as null. Those paths now use engine-neutral component ordering and an explicit empty-string default. The final matrix is green across all 27 checks. |
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.
Review
This extracts and expands the pivot-table behavior that was previously bundled into #331. It is the first PR in the stack; #331 will contain only relationship
create()support after this PR lands.Eloquent's belongs-to-many model is the reference point: related models always carry an intermediate model containing both pivot keys,
withPivot()selects additional columns,as()renames the accessor,using()selects a custom model, and the relationship owns pivot-specific query and write helpers. Reference: https://laravel.com/docs/12.x/eloquent-relationships#retrieving-intermediate-table-columnsQuick semantics and choices
BelongsToManyresult receives a loadedpivotrelationship containing both pivot keys.withPivot()adds declared columns.as()renames that loaded relationship, so normal Quick access such asgetSubscription()works.Pivot@quickmodel is read-only. Its schema is assembled at runtime, so allowingsave()would imply persistence guarantees Quick cannot safely make.using( "PostTag" )opts into a declared Pivot entity. It supports normal Quick properties, aliases, casts, methods, lifecycle hooks, and explicitsave(); it must extendquick.models.Relationships.Pivot.getPivotParent()andgetPivotRelated(), without introducing cascading persistence.withTimestamps()accepts explicit created/modified column names because Quick applications do not share one universal timestamp convention.attach()andsync()intentionally apply one pivot-attribute struct to every row. Per-ID attribute maps are not introduced in this PR.API
withPivot()as()using()withTimestamps()wherePivot(),orWherePivot()wherePivotIn(),wherePivotNotIn()wherePivotBetween(),wherePivotNotBetween()wherePivotNull(),wherePivotNotNull()orderByPivot(),orderByPivotDesc()withPivotValue()attach()andsync()updateExistingPivot()Test-first evidence
Before implementation, seven public relationship-flow specs errored because
withPivot(),using(), andwithTimestamps()did not exist. The tests exercise lazy and eager loading, the default and custom accessors, a custom Pivot cast and method, explicit custom-Pivot persistence, the read-only default model, pivot constraints/order, attachment attributes, updates, defaults, and timestamps.Validation
git diff --checkpassedSupports #84.