feat(database): add option to get underlying query for property relation#2102
feat(database): add option to get underlying query for property relation#2102laylatichy wants to merge 31 commits intotempestphp:3.xfrom
Conversation
Benchmark ResultsComparison of Open to see the benchmark resultsNo benchmark changes above ±5%. Generated by phpbench against commit 71ee424 |
debbc8f to
ceec41c
Compare
| $model = inspect(model: $this); | ||
|
|
||
| if (! $model->hasPrimaryKey() || ! $model->getPrimaryKeyProperty()->isInitialized(object: $this)) { | ||
| throw new InvalidArgumentException( |
There was a problem hiding this comment.
Can you add dedicated exceptions in Tempest\Database\Exceptions?
Our guidelines on exceptions are here: https://tempestphp.com/3.x/extra-topics/contributing#exception-classes
I did notice that we don't have any QueryBuilderException or DatabaseException interface yet, so you don't have to add these marker interfaces.
There was a problem hiding this comment.
added 2 exceptions
packages/database/src/Exceptions/PrimaryKeyWasNotInitialized.php
packages/database/src/Exceptions/PropertyWasNotARelation.php
…cit attr, unsaved model, nonexistent property, empty result)
…getHasManyThrough/getBelongsToMany calls
…ead of manual property check
…e, return QueryBuilder for select/update/delete support
…s all relation types
…longsToMany query()
…pe for subquery relations
…r BelongsToMany delete support
…e query() for relations
… a public instance method
… instead of duplicating pivot logic
b3187c9 to
6b0e889
Compare
…WasNotInitialized and PropertyWasNotARelation
6b0e889 to
1007539
Compare
…t 1G memory limit
b234fd9 to
71ee424
Compare
|
@brendt had to add If you want i can move that commit into separate pr 71ee424 |
|
No it's fine to keep it here. I'll review later today :) |
pr to add option to have similar behavior to laravels author->books() to get underlying query for property relation we can chain into
works with all relation types:
now, I wasnt sure about naming it but opted in for
querysince it returns querybuilder same as query() helper just scoped to model property