Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Validator] UniqueEntity allow use toString result for value #52348

Open
@oleg-andreyev

Description

@oleg-andreyev

Description

When you have a complex stmt

UniqueEntity(
    fields: ['product', 'supplier', 'validFrom', 'validTill', 'minOrderQty', 'isSale', 'isSpecial'],
    message: 'Purchase price ({{ value }}) already exists for the product',
),

it would be great to allow configure value as result of toString from current class.

Right now if errorPath is not defined, it will use first from criteria, if defined it will use only that "path" value.

Idea:
Create flag that will indicate to use toString of current class, it will allow set value of all values that current class has and will help to find/understand why current entity has failed.

Example

UniqueEntity(
    fields: ['product', 'supplier', 'validFrom', 'validTill', 'minOrderQty', 'isSale', 'isSpecial'],
    message: 'Purchase price ({{ value }}) already exists for the product',
),
public function __toString(): string
{
    return sprintf(
        '#%d, %s, Supplier: %s, Value: %s (%s to %s), MOQ: %s, Sale: %b, Special: %b',
        $this->id,
        $this->product?->getGtin(),
        $this->supplier?->getName(),
        $this->value,
        $this->validFrom?->format('Y-m-d') ?? '',
        $this->validTill?->format('Y-m-d') ?? '',
        $this->minOrderQty,
        $this->isSale,
        $this->isSpecial,
    );
}

Expected result:

Purchase price (ID, GTIN, SUPPLIER, VALUE, VALID FROM VALID TILL MOQ SALE SPECIAL) already exists for the product

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions