-
-
Notifications
You must be signed in to change notification settings - Fork 62
HasMany: removeAll #788
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
base: main
Are you sure you want to change the base?
HasMany: removeAll #788
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| /** | ||
| * @testCase | ||
| * @dataProvider ../../../databases.ini | ||
| */ | ||
|
|
||
| namespace NextrasTests\Orm\Integration\Relationships; | ||
|
|
||
|
|
||
| use NextrasTests\Orm\Author; | ||
| use NextrasTests\Orm\DataTestCase; | ||
| use NextrasTests\Orm\Tag; | ||
| use NextrasTests\Orm\TagFollower; | ||
| use Tester\Assert; | ||
|
|
||
|
|
||
| require_once __DIR__ . '/../../../bootstrap.php'; | ||
|
|
||
|
|
||
| class RelationshipOneHasManyRemoveAllTest extends DataTestCase | ||
| { | ||
|
|
||
| public function testRemoveAllItems(): void | ||
| { | ||
| $author = new Author(); | ||
| $author->name = 'Stephen King'; | ||
|
|
||
| $tagFollower = new TagFollower(); | ||
| $tagFollower->author = $author; | ||
| $tagFollower->tag = new Tag('Horror'); | ||
|
|
||
| $this->orm->authors->persistAndFlush($author); | ||
|
|
||
| Assert::same(1, $author->tagFollowers->count()); | ||
| $author->tagFollowers->removeAll(); | ||
| Assert::same(0, $author->tagFollowers->count()); | ||
|
|
||
| $this->orm->authors->persistAndFlush($author); | ||
|
|
||
| Assert::same(0, $author->tagFollowers->count()); | ||
| Assert::same(0, $author->tagFollowers->countStored()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| $test = new RelationshipOneHasManyRemoveAllTest(); | ||
| $test->run(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| START TRANSACTION; | ||
| INSERT INTO "public"."authors" ("name", "born_on", "web", "favorite_author_id") VALUES ('Stephen King', '2021-03-21'::date, 'http://www.example.com', NULL); | ||
| SELECT CURRVAL('public.authors_id_seq'); | ||
| INSERT INTO "tags" ("name", "is_global") VALUES ('Horror', 'y'); | ||
| SELECT CURRVAL('public.tags_id_seq'); | ||
| INSERT INTO "tag_followers" ("created_at", "author_id", "tag_id") VALUES ('2021-12-02 19:21:00.000000'::timestamptz, 3, 4); | ||
| COMMIT; | ||
| SELECT "tag_followers".* FROM "tag_followers" AS "tag_followers" WHERE "tag_followers"."author_id" IN (3); | ||
| SELECT "tag_followers".* FROM "tag_followers" AS "tag_followers" WHERE (NOT (("tag_followers"."author_id", "tag_followers"."tag_id") IN ((3, 4)))) AND ("tag_followers"."author_id" IN (3)); | ||
| START TRANSACTION; | ||
| COMMIT; | ||
|
Comment on lines
+10
to
+11
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :-O I do not. Hopefully, you have not discovered a bug.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks buggy to me.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh no, this is a real bug that has been hidden for many years. Expected behavior:
The second option is tracked in #205 and #278. Sadly, the current behavior does not rigger exception (either missing unsupported removeOrphan || non-nullable). Supporting removeOrphan is a bit more difficult - we need to rewrite PersistenceHelper & RemovalHelper -> join the implementation together -> since the wanted behavior is in RemovalHelper, but needs to be triggered from PersistenceHelper. As we are in the 5.1 RC phase, I would rather incline to trigger the exception. The working workaround is to call the TagFollower repository's |
||
| SELECT "tag_followers".* FROM "tag_followers" AS "tag_followers" WHERE "tag_followers"."author_id" IN (3); | ||
| SELECT "author_id", COUNT(DISTINCT "tag_followers"."tag_id") as "count" FROM "tag_followers" AS "tag_followers" WHERE "tag_followers"."author_id" IN (3) GROUP BY "author_id"; | ||
Uh oh!
There was an error while loading. Please reload this page.