You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using custom types, from some reason, when i use custom type as ID, its generate error.
Current behavior
Currently, its generate error Handling "App\Returns\Application\Command\CompleteReturnCommand" failed: Call to a member function __toString() on string
Expected behavior
I can read and update entities without modify convertToDatabaseValue method
How to reproduce
I have entity:
class CustomerReturn
{
public function __construct(
private ReturnId $id,
private OrderId $returningOrderId,
) {}
}
class OrderIdType extends Type
{
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return 'VARCHAR(36)';
}
public function convertToPHPValue($value, AbstractPlatform $platform): OrderId
{
return new OrderId($value);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform): string
{
return $value->__toString();
}
}
class ReturnIdType extends Type
{
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return 'VARCHAR(36)';
}
public function convertToPHPValue($value, AbstractPlatform $platform): ReturnId
{
return new ReturnId($value);
}
public function convertToDatabaseValue($value, AbstractPlatform $platform): string
{
return $value->__toString();
}
}
Objects:
class OrderId
{
public function __construct(
private string $id,
) {}
public static function fromString(string $id): OrderId
{
return new OrderId($id);
}
public function getId(): string
{
return $this->id;
}
public function __toString(): string
{
return $this->id;
}
}
class ReturnId
{
public function __construct(
private string $id,
) {}
public static function fromString(string $id): ReturnId
{
return new ReturnId($id);
}
public function getId(): string
{
return $this->id;
}
public function __toString(): string
{
return $this->id;
}
}
From unknown reason, i got error mentioned above. When i replace method in ReturnIdType to:
public function convertToDatabaseValue($value, AbstractPlatform $platform): string
{
if (is_string($value))
return $value;
return $value->__toString();
}
Everything works fine.
Only difference is one type i use as id field, and second as "normal" field.
The text was updated successfully, but these errors were encountered:
Bug Report
Summary
When using custom types, from some reason, when i use custom type as ID, its generate error.
Current behavior
Currently, its generate error
Handling "App\Returns\Application\Command\CompleteReturnCommand" failed: Call to a member function __toString() on string
Expected behavior
I can read and update entities without modify
convertToDatabaseValue
methodHow to reproduce
I have entity:
With mapping:
Types:
Objects:
From unknown reason, i got error mentioned above. When i replace method in ReturnIdType to:
Everything works fine.
Only difference is one type i use as id field, and second as "normal" field.
The text was updated successfully, but these errors were encountered: