Skip to content

Commit

Permalink
constrain is now not relation specific (!)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy-j committed Mar 28, 2019
1 parent de7bf7d commit 268b050
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
11 changes: 8 additions & 3 deletions src/Promise/PromiseOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ public function __scope(): array
public function __resolve()
{
if (!is_null($this->orm)) {
$key = key($this->scope);
$value = $this->scope[$key];
if (count($this->scope) !== 1) {
$this->resolved = $this->orm->getRepository($this->target)->findOne($this->scope);
} else {
$key = key($this->scope);
$value = $this->scope[$key];

$this->resolved = $this->orm->get($this->target, $key, $value, true);
}

$this->resolved = $this->orm->get($this->target, $key, $value, true);
$this->orm = null;
}

Expand Down
13 changes: 1 addition & 12 deletions src/Relation/Pivoted/PivotedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ class PivotedPromise implements PromiseInterface
/** @var mixed */
private $innerKey;

/** @var Select\ConstrainInterface|null */
private $constrain;

/** @var null|PivotedStorage */
private $resolved;

Expand All @@ -56,14 +53,6 @@ public function __construct(ORMInterface $orm, string $target, array $relationSc
$this->innerKey = $innerKey;
}

/**
* @param Select\ConstrainInterface $constrain
*/
public function setConstrain(?Select\ConstrainInterface $constrain)
{
$this->constrain = $constrain;
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -114,7 +103,7 @@ public function __resolve()

/** @var ManyToManyLoader $loader */
$loader = $loader->withContext($loader, [
'constrain' => $this->constrain,
'constrain' => $this->orm->getSource($this->target)->getConstrain(),
'as' => $table,
'method' => JoinableLoader::POSTLOAD
]);
Expand Down
2 changes: 1 addition & 1 deletion tests/ORM/Morphed/MorphedHasOnePromiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

namespace Cycle\ORM\Tests\Morphed;

use Cycle\ORM\Mapper\Mapper;
use Cycle\ORM\Heap\Heap;
use Cycle\ORM\Mapper\Mapper;
use Cycle\ORM\Promise\PromiseInterface;
use Cycle\ORM\Relation;
use Cycle\ORM\Schema;
Expand Down

0 comments on commit 268b050

Please sign in to comment.