-
Notifications
You must be signed in to change notification settings - Fork 48
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 checking of nested docs id in comparison check when updating document #304
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see if we can simplify some of the conditions to make it a bit easier to read
src/Database/Database.php
Outdated
$relationType = (string) $relationships[$key]['options']['relationType']; | ||
$side = (string) $relationships[$key]['options']['side']; | ||
switch($relationType) { | ||
case Database::RELATION_ONE_TO_ONE: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the curly braces around the switch cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we keep them? It allows me to minimize the whole case at once without curly brackets, it's not possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove them, they will be inconsistent with other switches, and we shouldn't change code style just for IDE features.
If you're using VS Code, you could change the folding strategy
to allow minimizing the whole case without changing code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice looks much better, just a few more style changes 👍
src/Database/Database.php
Outdated
(\is_null($oldValue) && !\is_null($value)) || | ||
(!is_null($oldValue) && \is_null($value)) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two can just be (\is_null($value) !== \is_null($oldValue))
src/Database/Database.php
Outdated
$shouldUpdate = true; | ||
break; | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's break from the if instead of nesting in an else
src/Database/Database.php
Outdated
$side = (string) $relationships[$key]['options']['side']; | ||
switch($relationType) { | ||
case Database::RELATION_ONE_TO_ONE: { | ||
$oldValue = $old->getAttribute($key) instanceof Document ? $old->getAttribute($key)->getId() : $old->getAttribute($key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's line break to make ternarys easier to read:
$oldValue = $old->getAttribute($key) instanceof Document ? $old->getAttribute($key)->getId() : $old->getAttribute($key); | |
$oldValue = $old->getAttribute($key) instanceof Document | |
? $old->getAttribute($key)->getId() | |
: $old->getAttribute($key); |
src/Database/Database.php
Outdated
break; | ||
} | ||
foreach ($value as $index=>$relation) { | ||
$oldValue = $old->getAttribute($key)[$index] instanceof Document ? $old->getAttribute($key)[$index]->getId() : $old->getAttribute($key)[$index]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's line break this too
src/Database/Database.php
Outdated
foreach ($value as $index=>$relation) { | ||
$oldValue = $old->getAttribute($key)[$index] instanceof Document ? $old->getAttribute($key)[$index]->getId() : $old->getAttribute($key)[$index]; | ||
if ( | ||
(\is_string($relation) && $oldValue!==$relation) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(\is_string($relation) && $oldValue!==$relation) || | |
(\is_string($relation) && $oldValue !== $relation) || |
src/Database/Database.php
Outdated
(\is_null($oldValue) && !\is_null($value)) || | ||
(!is_null($oldValue) && \is_null($value)) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two can just be (\is_null($value) !== \is_null($oldValue))
src/Database/Database.php
Outdated
(\is_null($old->getAttribute($key)) && !\is_null($value)) || | ||
(!is_null($old->getAttribute($key)) && \is_null($value)) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two can just be (\is_null($value) !== \is_null($oldValue))
src/Database/Database.php
Outdated
} | ||
// Compare if the document has any changes | ||
foreach ($document as $key=>$value) { | ||
// Skip the nested documents as they will be checked later in recursions. | ||
if (array_key_exists($key, $relationshipKeys)) { | ||
if (array_key_exists($key, $relationships)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (array_key_exists($key, $relationships)) { | |
if (\array_key_exists($key, $relationships)) { |
This PR checks the nested docs id to the old doc nested docs.
For example:
If document A is related to document B but we do not have permission to access it, we can still establish a relationship between document A and a different version of document B (let's call it B1). This is because we compare B to its previous version, and B1 to its previous version as well. If there are no changes in B1, then we do not need permission to relate it to document A.