Skip to content

Same twoWayKey - #327

Closed
fogelito wants to merge 3 commits into
mainfrom
relation-same-key
Closed

Same twoWayKey#327
fogelito wants to merge 3 commits into
mainfrom
relation-same-key

Conversation

@fogelito

Copy link
Copy Markdown
Contributor

No description provided.

Comment threadtests/Database/Base.php Outdated
Comment threadtests/Database/Base.php Outdated
Comment threadsrc/Database/Database.php Outdated
fogelitoand others added 2 commits October 2, 2023 10:40
Comment on lines +1540 to 1549
try {
if ($attribute->getAttribute('type') === self::VAR_RELATIONSHIP
&& \strtolower($attribute->getAttribute('options')['twoWayKey']) === \strtolower($twoWayKey)
&& $attribute->getAttribute('options')['relatedCollection'] === $relatedCollection->getId()
) {
throw new DuplicateException('Related attribute already exists');
}
} catch (DuplicateException $e) {
$twoWayKey ??= $collection->getId() . '_' . uniqid();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a try/catch here, we can use use the if:

Suggested change
try {
if ($attribute->getAttribute('type') === self::VAR_RELATIONSHIP
&& \strtolower($attribute->getAttribute('options')['twoWayKey']) === \strtolower($twoWayKey)
&& $attribute->getAttribute('options')['relatedCollection'] === $relatedCollection->getId()
) {
thrownewDuplicateException('Related attribute already exists');
}
} catch (DuplicateException $e) {
$twoWayKey ??= $collection->getId() . '_' . uniqid();
}
if ($attribute->getAttribute('type') === self::VAR_RELATIONSHIP
&& \strtolower($attribute->getAttribute('options')['twoWayKey']) === \strtolower($twoWayKey)
&& $attribute->getAttribute('options')['relatedCollection'] === $relatedCollection->getId()
) {
$twoWayKey ??= $collection->getId() . '_' . uniqid();
}

throw new DuplicateException('Related attribute already exists');
}
} catch (DuplicateException $e) {
$twoWayKey ??= $collection->getId() . '_' . uniqid();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be $twoWayKey = $collection->getId() . '_' . uniqid();, otherwise it will only assign if null

@fogelito

Copy link
Copy Markdown
ContributorAuthor

We tool care of this on Appwrite side

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@fogelito@abnegate