Skip to content

Laravel ModelMetadata fails to correcctly detect primary and regular indexes #7182

Closed
@maxmishyn

Description

@maxmishyn

API Platform version(s) affected: 4.x

Description
While workign on Laravel based project I've faced problem with PUT method in standard mode. It fails to update fields which have indexes.

How to reproduce
Define any non-primary field as index. Make PUL query to replace the record. As a result only non-indexed fields will be updated. No exceptions or error messages triggered.

Possible Solution
Adter some investigations I've found possible bug in the implementation of ApiPlatform\Laravel\Eloquent\Metadata\ModelMetadata class.

Eaxactly isColumnPrimaryKey method:

        foreach ($indexes as $index) {
            if (\in_array($column, $index['columns'], true)) {
                return true;
            }
        }

This metod returns true whenever field is listed in the $indexes. What to my mind is wrong. Possible solution:

        foreach ($indexes as $index) {
            if (\in_array($column, $index['columns'], true)) {
                return $index['primary'];
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions