Skip to content

[BUG]: readAttribute() receives an array on a composite through-relation with reusable #17560

Description

@niden

$fields = $relation->getFields() is an array for a composite relation. The code just above handles that correctly when building the conditions:

if (is_array($fields)) {
    // ... $record->readAttribute($fields[$i])
} else {
    // ... $record->readAttribute($fields)
}

The reusable-cache key below it has no such guard:

$uniqueKey = $this->getUniqueKey(
    $record,
    $referencedModel,
    [$intermediateModel, $parameters, $record->readAttribute($fields)]
);

readAttribute() takes a string, so a composite through-relation declared with reusable => true passes an array and fatals.

Expected

The cache key is built from every field the relation covers, the same way the conditions above it are.

Note

Even if the type error is only sidestepped, reading a single attribute for a composite relation would produce the same key for different records, so the reuse cache would return the wrong rows. The key has to include all the fields.

Not affected

Manager.php:1609 and :1734 reach readAttribute($fields) only inside an is_array() branch, so they are correct as they stand.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

5.0The issues we want to solve in the 5.0 releasebugA bug reportstatus: mediumMedium

Type

Projects

  • Status
    Implemented

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions