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

Same twoWayKey #327

Closed
wants to merge 3 commits into from
Closed

Same twoWayKey #327

wants to merge 3 commits into from

Conversation

fogelito
Copy link
Contributor

@fogelito fogelito commented Oct 1, 2023

No description provided.

tests/Database/Base.php Outdated Show resolved Hide resolved
tests/Database/Base.php Outdated Show resolved Hide resolved
src/Database/Database.php Outdated Show resolved Hide resolved
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
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()
) {
throw new DuplicateException('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
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
Contributor Author

We tool care of this on Appwrite side

Sign up for free to 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