Repository navigation
Optional relationship keys and typed relation classes - #377
Merged
Merged
Conversation
added 4 commits
October 16, 2026 23:13
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.
Pull Request Checklist
Summary
Relationship methods now work with just the related model, and they return their own classes so you can declare a return type.
Before, this was not possible. All the key arguments were required, and the methods returned a plain
Builder, so there was no class to put in a return type.The problems
linkOne,linkMany,bindToandbindToManyall required their foreign key, local key and pivot table arguments. In almost every app these follow the same naming convention, so users repeated the same strings in every model.Builderwith no declared type. Writing: LinkOnefailed because the class did not exist, and users could not annotate relationship methods with anything more specific thanBuilder.Typed relation classes
Four new classes in
Phaseolies\Database\Entity\Relations:linkOne()LinkOnelinkMany()LinkManybindTo()BindTobindToMany()BindToManyEach one extends
Builderand adds no behavior. Everything that worked on a relation query (where(),orderBy(),count(),first()) still works. Existing return types ofBuilderstay valid.Docs
relationships.mdin the docs repo has a new "Relationship Return Types" section. The four relationship examples now use the short form with a return type, and each comes with a table of arguments and defaults. The "all the arguments are mandatory" sentences were removed.Checklist