Skip to content

Loading…

DDC-1061: Allow datetime field in a composite primary key #1653

Closed
doctrinebot opened this Issue · 8 comments

2 participants

@doctrinebot

Jira issue originally created by user stof:

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.

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Issue was closed with resolution "Invalid"

@doctrinebot

Comment created by seldaek:

Igor worked on a patch igorw/doctrine2@2.1.x...[DDC-1061](http://www.doctrine-project.org/jira/browse/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.

@doctrinebot

Comment created by @beberlei:

There is also #232

@doctrinebot

Comment created by stof:

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

@doctrinebot

Comment created by @beberlei:

A related Github Pull-Request [GH-232] was
#232

@doctrinebot

Comment created by darkangel:

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?

@doctrinebot

Comment created by @ocramius:

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

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.