Hi

After listening to a talk by Ocramius, I wanted to try migrating my 
application to uuid primary keys.

I first installed ramsey/uuid and then found out about ramsey/uuid-doctrine. 
I sucessfully installed and used both and ended up with a generatedValue 
for my primary key with a custom type (UuidInterface in php, uuid in 
doctrine annotation) from ramsey's library.

It worked fine but I still had an ID generated at insertion, which means my 
Entity can't be in a valid state all the time. I removed the custom type 
and I tried to implement it by myself.

I added a $this->id = Uuid::uuid4() to my constructor and went from that. I 
got it to working fine but it was storing the uuid to a char(36) type which 
the Ocramius talk warned about.

I tried to switch to binary instead, here are the changes I had to address:
- replace the id with Uuid::uuid4()->getBytes() to generate the binary 
content
- change the type to binary(16) in doctrine annotation
- I couldn't work with the UuidInterface anymore as getBytes() return a 
string, so I had to switch php type to string (I'm working with fully 
declared types hint with php so I had no choice)

However, my application is now broken. I used to pass whole entities for 
doctrine to use as foreign keys on ManyToOne columns, at insertion I get 
this error:

> INSERT INTO issue (iss_id, iss_resolved, iss_project_line_content, 
> iss_first_ins_id, iss_last_ins_id, iss_resolved_imp_id) VALUES (?, ?, ?, ?, 
> ?, ?)' with params ["
> \x36\x14\x05\x08\x03\x92\x4b\xc7\x9a\x1c\x43\x5f\x12\x7f\xc7\x
> b4", 0, "var $consumed = '';", Resource id #328, Resource id #328, null]:
> SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint 
> failed: issue.iss_last_ins_id#0 
> [path]\vendor\doctrine\dbal\lib\Doctrine\DBAL\DBALException.php(169): 
> Doctrine\DBAL\Driver\AbstractSQLiteDriver->convertException('
> An exception oc...', Object(Doctrine\DBAL\Driver\PDOException))


In blue, it's the binary uuid string, and in red, it's the entities that 
were passed to the other entity for the foreign key.

I tried to resolve this by stopping passing whole entities between each 
other and only passing Id, so I had to change the whole types, but I then 
have an other error

PHP Fatal error:  Uncaught TypeError: Return value of 
> App\Entity\Inspection::getId() must be of the type string, resource 
> returned in [path]


It seems that now all my Ids are returned by doctrine in resource type and 
I don't understand why or what to do about it.

Could anyone give me a tip to what I'm doing wrong? Or maybe point me to a 
github project who successfully use uuid with binary types (In a database 
where uuid are not a native type)?

Please tell me if you need examples of code. I tried to summarize 
everything but maybe I missed something.

Thanks a lot!

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to