Skip to content

Commit

Permalink
Merge pull request #74 from mishfish/todo-fix
Browse files Browse the repository at this point in the history
fix todo - inverse ContextTrait::isNotNullable logic
  • Loading branch information
wolfy-j committed Feb 19, 2020
2 parents f144d1f + 5ddfceb commit 8b1b0d0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
10 changes: 4 additions & 6 deletions src/Relation/AbstractRelation.php
Expand Up @@ -105,17 +105,15 @@ public function extract($data)
}

/**
* Indicates that relation can not be nullable.
*
* @return bool
* @inheritDoc
*/
protected function isNotNullable(): bool
protected function isNullable(): bool
{
if (array_key_exists(Relation::NULLABLE, $this->schema)) {
return !$this->schema[Relation::NULLABLE];
return $this->schema[Relation::NULLABLE];
}

return true;
return false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Relation/BelongsTo.php
Expand Up @@ -33,7 +33,7 @@ class BelongsTo extends AbstractRelation implements DependencyInterface
public function queue(CC $store, $entity, Node $node, $related, $original): CommandInterface
{
if ($related === null) {
if ($this->isNotNullable()) {
if (!$this->isNullable()) {
throw new NullException("Relation {$this} can not be null");
}

Expand Down
2 changes: 1 addition & 1 deletion src/Relation/HasMany.php
Expand Up @@ -161,7 +161,7 @@ protected function queueDelete($related): CommandInterface
{
$rNode = $this->getNode($related);

if (!$this->isNotNullable()) {
if ($this->isNullable()) {
$store = $this->orm->queueStore($related);
$store->register($this->outerKey, null, true);
$rNode->getState()->decClaim();
Expand Down
2 changes: 1 addition & 1 deletion src/Relation/HasOne.php
Expand Up @@ -85,7 +85,7 @@ protected function deleteOriginal($original): CommandInterface
{
$rNode = $this->getNode($original);

if (!$this->isNotNullable()) {
if ($this->isNullable()) {
$store = $this->orm->queueStore($original);
$store->register($this->outerKey, null, true);
$rNode->getState()->decClaim();
Expand Down
7 changes: 3 additions & 4 deletions src/Relation/Traits/ContextTrait.php
Expand Up @@ -24,12 +24,11 @@ trait ContextTrait
{

/**
* True is given relation is required for the object to be saved (i.e. NOT NULL).
* True if given relation is not required for the object to be saved (i.e. NULL).
*
* @todo rename to isNullable and inverse the logic
* @return bool
*/
abstract public function isNotNullable(): bool;
abstract public function isNullable(): bool;
/**
* Configure context parameter using value from parent entity. Created promise.
*
Expand All @@ -45,7 +44,7 @@ protected function forwardContext(Node $from, string $fromKey, CC $carrier, Node
$toColumn = $this->columnName($to, $toKey);

// do not execute until the key is given
$carrier->waitContext($toColumn, $this->isNotNullable());
$carrier->waitContext($toColumn, !$this->isNullable());

// forward key from state to the command (on change)
$to->forward($toKey, $carrier, $toColumn);
Expand Down

0 comments on commit 8b1b0d0

Please sign in to comment.