Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1061

Allow datetime field in a composite primary key

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      The current implementation concatenates the fields used in a primary key. This does not work for datetime fields as a DateTime object is not castable as string. It would be useful to allow them to be used in primary keys too.

        Activity

        Hide
        Benjamin Eberlei added a comment -

        A "general" fix would be much to expensive in php userland. What you can do is implement your own datetime type for this purpose that creates a DateTime derivate that implements __toString()

        Show
        Benjamin Eberlei added a comment - A "general" fix would be much to expensive in php userland. What you can do is implement your own datetime type for this purpose that creates a DateTime derivate that implements __toString()
        Hide
        Jordi Boggiano added a comment -

        Igor worked on a patch https://github.com/igorw/doctrine2/compare/2.1.x...DDC-1061 - not sure what the perf impact is, but it sure would be nice to support this, or at least to throw an exception or something more obvious than how it currently behaves.

        Show
        Jordi Boggiano added a comment - Igor worked on a patch https://github.com/igorw/doctrine2/compare/2.1.x...DDC-1061 - not sure what the perf impact is, but it sure would be nice to support this, or at least to throw an exception or something more obvious than how it currently behaves.
        Hide
        Benjamin Eberlei added a comment -
        Show
        Benjamin Eberlei added a comment - There is also https://github.com/doctrine/doctrine2/pull/232
        Hide
        Christophe Coevoet added a comment -

        The work done by Igor is flawed: the object will be hydrated several times because different DB call will return different DateTime instances, thus leading to a different hash in the UoW

        Show
        Christophe Coevoet added a comment - The work done by Igor is flawed: the object will be hydrated several times because different DB call will return different DateTime instances, thus leading to a different hash in the UoW
        Hide
        Benjamin Eberlei added a comment -

        A related Github Pull-Request [GH-232] was
        https://github.com/doctrine/doctrine2/pull/232

        Show
        Benjamin Eberlei added a comment - A related Github Pull-Request [GH-232] was https://github.com/doctrine/doctrine2/pull/232
        Hide
        Glen Ainscow added a comment -

        Please consider reopening this, it seems a bit crazy that you can't use a date or datetime field in a composite PK.

        Does checking if the field is an instance of DateTime and if so calling getTimestamp() or format('c') really affect the performance significantly?

        Show
        Glen Ainscow added a comment - Please consider reopening this, it seems a bit crazy that you can't use a date or datetime field in a composite PK. Does checking if the field is an instance of DateTime and if so calling getTimestamp() or format('c') really affect the performance significantly?
        Hide
        Marco Pivetta added a comment -

        It does not only affect performance, it is also an opinionated approach.

        If you need to use a datetime within a PK, simply provide an implementation of `DateTime` that includes `__toString`

        Show
        Marco Pivetta added a comment - It does not only affect performance, it is also an opinionated approach. If you need to use a datetime within a PK, simply provide an implementation of `DateTime` that includes `__toString`

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Christophe Coevoet
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: