Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Laravel-style relations #167

Merged
merged 66 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
cbaa2e5
WIP Laravel style relations
bennothommo Feb 19, 2024
8412881
Discard filesystem test case.
bennothommo Feb 19, 2024
f2c68ce
Add BelongsToMany, HasMany and HasOne tests
bennothommo Feb 19, 2024
49949fa
Remove unneeded relation class.
bennothommo Feb 22, 2024
80a853a
Add HasManyThrough, HasOneThrough, MorphMany and MorphOne tests
bennothommo Feb 22, 2024
a79bbb4
Move performDeleteOnRelations method into HasRelationship concern
bennothommo Feb 22, 2024
6c5c7ad
Significantly refactor relation construction.
bennothommo Feb 22, 2024
55f03dc
Add ability to define relations (through methods) as dependent.
bennothommo Feb 22, 2024
e8e093a
Fix Stan issue
bennothommo Feb 22, 2024
583051b
Add array schema for relations, add custom return types for relation …
bennothommo Feb 22, 2024
173c752
Fix relation name for attachments
bennothommo Feb 22, 2024
39453b1
Allow dependent model to be marked as not dependent
bennothommo Feb 23, 2024
ce5ddf0
Shore up API, strengthen types, remove validation method
bennothommo Feb 23, 2024
8594a13
Minor
bennothommo Feb 23, 2024
7fd53cd
Add ability to define model as pushable, add all relation definitions
bennothommo Feb 23, 2024
426a2d4
Add ability to define detachable relations
bennothommo Feb 23, 2024
cd3e791
Add attachment tests
bennothommo Feb 23, 2024
ee17333
Fix attachment relations
bennothommo Feb 23, 2024
8a2d88e
Copilot went a bit hog-wild on that one
bennothommo Feb 23, 2024
c9414e1
Fix Stan issue
bennothommo Feb 23, 2024
b93e935
Rename MigratesForTest class
bennothommo Feb 26, 2024
d4c1191
Move Sortable trait tests
bennothommo Feb 26, 2024
3ac262d
Merge remote-tracking branch 'origin/develop' into wip/laravel-style-…
bennothommo Feb 26, 2024
bdc3849
Add extension support for relations, add support for SoftDelete trait
bennothommo Feb 26, 2024
a84b1a2
Merge branch 'develop' into wip/laravel-style-relations
bennothommo Feb 26, 2024
19b3f1a
Bring in all remaining tests from core
bennothommo Feb 26, 2024
a2b12e5
Fix soft deletion
bennothommo Feb 27, 2024
06f7b69
Add soft delete tests specifically with Laravel relations
bennothommo Feb 27, 2024
0c2e944
Merge branch 'develop' into wip/laravel-style-relations
bennothommo Mar 25, 2024
2bde984
Merge branch 'fix-through-relations' into wip/laravel-style-relations
bennothommo Mar 28, 2024
0204a0c
Merge branch 'develop' into wip/laravel-style-relations
bennothommo Jul 28, 2024
8337ae7
Fix database test cases not always running migrations
bennothommo Jul 29, 2024
e0e4676
Fix count-only relations.
bennothommo Jul 29, 2024
1137eb5
Fix definition
bennothommo Jul 29, 2024
c82a43f
Apply count constraint directly on relation
bennothommo Jul 29, 2024
3fcb603
Fix Stan issues
bennothommo Jul 29, 2024
c4abef8
Fix support for pivot models
bennothommo Jul 29, 2024
46778f5
Update src/Database/Relations/Concerns/DefinedConstraints.php
bennothommo Jul 29, 2024
11064ed
Update src/Database/Relations/Concerns/CanBeCounted.php
bennothommo Jul 30, 2024
4d1d1d4
Update src/Database/Relations/Concerns/CanBeCounted.php
bennothommo Jul 30, 2024
192b47d
Update src/Database/Relations/BelongsToMany.php
bennothommo Jul 30, 2024
57c22ba
Update src/Database/Relations/BelongsToMany.php
bennothommo Jul 30, 2024
9d6b829
Update src/Database/Relations/BelongsToMany.php
bennothommo Jul 30, 2024
2951b5c
Update src/Database/Relations/BelongsToMany.php
bennothommo Jul 30, 2024
248397b
Update src/Database/Relations/BelongsToMany.php
bennothommo Jul 30, 2024
500c32b
Update src/Database/Model.php
bennothommo Jul 30, 2024
e48418b
Update src/Database/Relations/BelongsToMany.php
bennothommo Jul 30, 2024
abcf7ee
Merge branch 'develop' into wip/laravel-style-relations
bennothommo Jul 30, 2024
49d581d
Update src/Database/Relations/Concerns/DefinedConstraints.php
bennothommo Jul 31, 2024
90adf97
Merge branch 'develop' into wip/laravel-style-relations
bennothommo Aug 16, 2024
9840073
Optimise conditions for applying traits and constraints to relation
bennothommo Aug 16, 2024
dd78973
Fix Stan issues
bennothommo Aug 16, 2024
5f6eb37
Stop double-defining of soft delete trait's dynamic methods and prope…
bennothommo Aug 16, 2024
9b056bf
Use alternative method for defining soft deletable relations
bennothommo Sep 2, 2024
267187b
Stan fixes
bennothommo Sep 2, 2024
fe2fdec
Merge branch 'develop' into wip/laravel-style-relations
bennothommo Oct 7, 2024
eb815a9
Add support for dynamic Laravel-style relations through Extension
bennothommo Oct 7, 2024
f8ee9d7
Stan fix
bennothommo Oct 7, 2024
2c8972b
Fix infinite loop, improve support for dynamic Laravel relations, imp…
bennothommo Oct 8, 2024
bbddb54
Stan fix
bennothommo Oct 8, 2024
9867c26
Allow relation flags to be toggled
bennothommo Oct 8, 2024
13e66cf
Minor
bennothommo Oct 8, 2024
55603fc
Detect relation conflicts
bennothommo Oct 8, 2024
0775c36
Fix code smell
bennothommo Oct 8, 2024
98a2247
Use SystemException rather than ApplicationException
bennothommo Oct 8, 2024
7a875c8
Fix tests
bennothommo Oct 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php",
"tests/DbTestCase.php"
],
"psr-4": {
"Winter\\Storm\\Tests\\": "tests/"
}
Expand Down
297 changes: 86 additions & 211 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ parameters:
- src/Parse/PHP/ArrayPrinter.php
- src/Foundation/Console/KeyGenerateCommand.php
- src/Scaffold/GeneratorCommand.php
ignoreErrors:
- message: '#Call to private method select\(\)#'
paths:
- src/Database/Relations/Concerns/CanBeCounted.php
disableSchemaScan: true
databaseMigrationsPath:
- src/Auth/Migrations
Expand Down
5 changes: 5 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
Expand All @@ -20,4 +21,8 @@
<directory>./tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="testing"/>
</php>
</phpunit>
55 changes: 55 additions & 0 deletions src/Database/Attributes/Relation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Winter\Storm\Database\Attributes;

use Attribute;
use Winter\Storm\Database\Relations\AttachMany;
use Winter\Storm\Database\Relations\AttachOne;
use Winter\Storm\Database\Relations\BelongsTo;
use Winter\Storm\Database\Relations\BelongsToMany;
use Winter\Storm\Database\Relations\HasMany;
use Winter\Storm\Database\Relations\HasManyThrough;
use Winter\Storm\Database\Relations\HasOne;
use Winter\Storm\Database\Relations\HasOneThrough;
use Winter\Storm\Database\Relations\MorphMany;
use Winter\Storm\Database\Relations\MorphOne;
use Winter\Storm\Database\Relations\MorphTo;
use Winter\Storm\Database\Relations\MorphToMany;

#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_FUNCTION)]
class Relation
{
private string $type;

public static array $relationTypes = [
'hasOne' => HasOne::class,
'hasMany' => HasMany::class,
'belongsTo' => BelongsTo::class,
'belongsToMany' => BelongsToMany::class,
'morphTo' => MorphTo::class,
'morphOne' => MorphOne::class,
'morphMany' => MorphMany::class,
'morphToMany' => MorphToMany::class,
'morphedByMany' => MorphToMany::class,
'attachOne' => AttachOne::class,
'attachMany' => AttachMany::class,
'hasOneThrough' => HasOneThrough::class,
'hasManyThrough' => HasManyThrough::class,
];

public function __construct(string $type)
{
if (in_array($type, array_keys(static::$relationTypes))) {
$this->type = $type;
} elseif (in_array($type, array_values(static::$relationTypes))) {
$this->type = array_search($type, static::$relationTypes);
} else {
throw new \Exception('Invalid relation type');
}
}

public function getType(): string
{
return $this->type;
}
}
mjauvin marked this conversation as resolved.
Show resolved Hide resolved
Loading