Code Monkey home page Code Monkey logo

Comments (5)

ramsey avatar ramsey commented on May 26, 2024

You're right. The test fails:

1) Ramsey\Uuid\Doctrine\UuidBinaryOrderedTimeTypeTest::testGettersReturnSameValuesAfterDatabaseRoundtrip
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-Binary String: 0xff6f8cb0c57d11e19b210800200c9a66
+Binary String: 0x11e1c57dff6f8cb09b210800200c9a66

I know it seems awkward, but this is how the OrderedTimeCodec works.

When it decodes the bytes, it puts them back into the order specified by the RFC, but when you get the bytes (using getBytes()) to put them into a database, it returns the bytes in the "ordered time" order, which rearranges the time fields, so that it can be stored in such a way that the table can be sorted by the UUIDs, and they'll be sorted in the order in which they were created.

What's happening in the test you've provided is that Uuid::fromString() is creating a standard Uuid object. There's nothing special about it. So, when you call getBytes(), they're in the proper order, as defined by the RFC. But when you pass that Uuid object into convertToDatabaseValue() for the UuidBinaryOrderedTimeType, then it gets converted into a special type of Uuid, where the bytes are re-arranged for sorting by "ordered time." When you call convertToPHPValue() for the same type, it maintains this special type and returns a Uuid object in which the return value of getBytes() will always return the bytes in the "ordered time" format, even though the hex values a rendered properly, according to the RFC definition.

Does that help clear things up? If not, feel free to ask more questions.

from uuid-doctrine.

weirdan avatar weirdan commented on May 26, 2024

Well, you've just reiterated what I already stated in the initial bug report. Rehydrated UUID has a different codec, that affects its behavior (= 'converted into a special type of Uuid, where the bytes are re-arranged for sorting by "ordered time."'). It wasn't there before it hit the db, it doesn't need to be there when it gets back.

from uuid-doctrine.

ramsey avatar ramsey commented on May 26, 2024

It wasn't there before it hit the db, it doesn't need to be there when it gets back.

Iā€™m not sure what this means.

When you use the UuidBinaryOrderedTimeType, it converts the UUID into this special type. If you need the bytes to remain the same before and after, use the UuidBinaryType instead to pass the UUID into the database and back.

from uuid-doctrine.

weirdan avatar weirdan commented on May 26, 2024

it converts the UUID into this special type.

Right. And it doesn't need to do that, as far as Doctrine type handling is concerned. Type converter gets binary string and returns a UUID. Which has no reason to be any kind of special sub-specie. Could have been ordinary UUID just as well, so it wouldn't be breaking storage transparency.

from uuid-doctrine.

ramsey avatar ramsey commented on May 26, 2024

The point of using the OrderedTimeCodec is to rearrange the bytes in just this way.

from uuid-doctrine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.