Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom types converted to database value by __toString() in loadAll instead of Type::convertToDatabaseValue() #11405

Open
hlib-kuznetsov opened this issue Mar 29, 2024 · 3 comments
Assignees

Comments

@hlib-kuznetsov
Copy link

hlib-kuznetsov commented Mar 29, 2024

Bug Report

Q A
BC Break idk
Version 3.1.1

Summary

When eager relations are loaded by BasicEntityPersister::loadAll()

[$params, $types] = $this->expandParameters($criteria);

There only 3 options for array type - STRING, INTEGER and ASCII

return match ($type) {
ParameterType::STRING => ArrayParameterType::STRING,
ParameterType::INTEGER => ArrayParameterType::INTEGER,
ParameterType::ASCII => ArrayParameterType::ASCII,
};

So any custom type will be narrowed to one of those types, based on Type::getBindingType() or will fail.

var_dump($criteria);
[$params, $types] = $this->expandParameters($criteria);
var_dump($params, $types);
array(1) {
  [0]=>
  array(1) {
    [0]=>
    object(Symfony\Component\Uid\Ulid)#814 (1) {
      ["uid":protected]=>
      string(26) "01HKQA3CFEMF71KWYC3QN7W87K"
    }
  }
}
array(1) {
  [0]=>
  enum(Doctrine\DBAL\ArrayParameterType::STRING)
}

Then when \Doctrine\DBAL\Connection binds values using Type::convertToDatabaseValue() any custom type, including Symfony\Uuid will be converted using STRING, INTEGER or ASCII convertToDatabaseValue(), not the type's one.

Current behavior

Eager relations refering to custom types are not loaded which leads to additional lazy queries

How to reproduce

Try eager loading when relation refers to column with any custom type, including uuid

Expected behavior

Custom types are bound to statement using convertToDatabaseValue(), not using __toString()

@beberlei beberlei self-assigned this Mar 31, 2024
@beberlei
Copy link
Member

Could this be related to new eager loading of one to many associations?

@michanismus
Copy link

Same for me and my custom Uuid implementation. Database type is binary and the php type is a string.
Relations with EAGER loading will always return an empty result. The parameter type is string without being converted to real binary database representation.

Last working version for me: 2.16.3

@pauci
Copy link

pauci commented Apr 5, 2024

I'm affected by this issue too. With database type integer, mapped to custom value object PurchaseId, I'm getting error Object of class PurchaseId could not be converted to int

Stuck on 2.16.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants