See the section of the uuid-doctrine README I linked in my previous reply.
The package provides two types: 'uuid' and 'uuid_binary'.  You were getting
CHAR(36) because you were using 'uuid' in your mapping.  Use 'uuid_binary'
to get a binary column.

On Mon, Jan 28, 2019, 9:18 AM Ronan Morin <[email protected] wrote:

> Hi Tim,
>
> Thank you for your answer!
>
> Yeah, I did add the type with ramsey/uuid-doctrine and it worked well but
> there was 2 issues:
> - The Id was handled by Doctrine at the insertion, which means the Id
> wasn't generated until the insertion in Database, which was the opposite of
> the advice in the talk (Maybe this issue can be solved by removing
> @GeneratedValue(strategy="CUSTOM") in my annotations and setting it by
> myself in the constructor)
> - The type chosen by ramsey/uuid-doctrine is char(36) for sqlite
> (returned by doctrine/dbal) and the talk was warning about that too.
>
> That's why I wanted to try to do it without ramsey/uuid-doctrine.
>
> If I want to set the type myself, I'm forced to ditch the "uuid" type in
> annotations, and if I do, I'm afraid Doctrine won't know what to do with
> the Uuid from ramsey/uuid. That's why I called the getBytes myself...
>
> I will try some tweaks, if you happen to have an idea, I would gladly take
> it!
>
> Thanks again!
>
> Le lundi 28 janvier 2019 17:44:20 UTC+1, Tim a écrit :
>>
>> IIRC, you shouldn't be using getBytes() at all.
>> Ramsey\Uuid\Doctrine\UuidBinaryType should be converting string-uuids
>> to/from the binary representation behind the scenes.  The $id property on
>> your entities should remain a string.
>>
>> Are you doing this already:
>> https://github.com/ramsey/uuid-doctrine#binary-database-columns ?
>>
>>
>>
>> On Sat, Jan 26, 2019 at 6:28 AM Ronan Morin <[email protected]> wrote:
>>
>>> 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.
>>>
>> --
> 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.
>

-- 
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