Skip to content

Commit

Permalink
Don't set the owner for valueGetter()
Browse files Browse the repository at this point in the history
fixes scenario 2
  • Loading branch information
brandonkelly committed May 14, 2024
1 parent 6a427e0 commit c12497f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static function entryManager(self $field): NestedElementManager
return array_map(fn($match) => (int)$match, $matches[1]);
}, self::fieldInstances($owner, $field)));

$query = self::createEntryQuery($owner, $field)
$query = self::createEntryQuery($owner, $field, false)
->where(['in', 'elements.id', $entryIds])
->trashed(null);

Expand Down Expand Up @@ -207,7 +207,7 @@ private static function fieldInstances(ElementInterface $element, self $field):
return array_values(array_filter($customFields, fn(FieldInterface $f) => $f->id === $field->id));
}

private static function createEntryQuery(?ElementInterface $owner, self $field): EntryQuery
private static function createEntryQuery(?ElementInterface $owner, self $field, bool $setOwner = true): EntryQuery
{
$query = Entry::find();

Expand All @@ -217,8 +217,10 @@ private static function createEntryQuery(?ElementInterface $owner, self $field):
ElementQuery::EVENT_BEFORE_PREPARE => function(
CancelableEvent $event,
EntryQuery $query,
) use ($owner) {
$query->ownerId = $owner->id;
) use ($owner, $setOwner) {
if ($setOwner) {
$query->ownerId = $owner->id;
}

// Clear out id=false if this query was populated previously
if ($query->id === false) {
Expand Down

0 comments on commit c12497f

Please sign in to comment.