Skip to content

Commit

Permalink
fix(db): allow passing only relationship_ids to fetch relationships
Browse files Browse the repository at this point in the history
ref #14332
  • Loading branch information
jdalsem committed Jun 15, 2023
1 parent 8bfe76e commit ad06ace
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Expand Up @@ -644,7 +644,7 @@ protected function normalizeRelationshipOptions(array $options = []) {
continue;
}

if (!$pair['relationship'] && !$pair['guid']) {
if (!$pair['relationship'] && !$pair['guid'] && !$pair['ids']) {
unset($options['relationship_pairs'][$key]);
continue;
}
Expand Down
20 changes: 17 additions & 3 deletions engine/tests/phpunit/unit/Elgg/Database/QueryOptionsUnitTest.php
Expand Up @@ -941,7 +941,7 @@ public function testNormalizesAnnotationSortingOptionsWithOrderBy() {
$this->assertEquals(null, $pair->sort_by_direction);
}

public function testNormalizeReltionshipOptions() {
public function testNormalizeRelationshipOptions() {
$after = (new \DateTime())->modify('-1 day');
$before = (new \DateTime());

Expand Down Expand Up @@ -970,7 +970,7 @@ public function testNormalizeReltionshipOptions() {
$this->assertEquals($before, $pair->created_before);
}

public function testNormalizeReltionshipOptionsForInverseRelationship() {
public function testNormalizeRelationshipOptionsForInverseRelationship() {
$after = (new \DateTime())->modify('-1 day');
$before = (new \DateTime());

Expand Down Expand Up @@ -999,7 +999,7 @@ public function testNormalizeReltionshipOptionsForInverseRelationship() {
$this->assertEquals($before, $pair->created_before);
}

public function testNormalizeReltionshipOnMultipleCalls() {
public function testNormalizeRelationshipOnMultipleCalls() {
$after = (new \DateTime())->modify('-1 day');
$before = (new \DateTime());

Expand All @@ -1015,6 +1015,20 @@ public function testNormalizeReltionshipOnMultipleCalls() {

$this->assertEquals($options, $this->options->normalizeOptions($options));
}

public function testIncompleteRelationshipPairOptions() {
$options = $this->options->normalizeOptions();
$this->assertEmpty($options['relationship_pairs']);

$options = $this->options->normalizeOptions([
'inverse_relationship' => false,
'relationship_join_on' => 'guid',
'relationship_created_after' => (new \DateTime())->modify('-1 day'),
'relationship_created_before' => (new \DateTime()),
]);

$this->assertEmpty($options['relationship_pairs']);
}

public function testNormalizeSelectClauses() {

Expand Down

0 comments on commit ad06ace

Please sign in to comment.