Skip to content

Loading…

DDC-2487: UnitOfWork::getEntityIdentifier() contains objects when custom mapping types are part of an entity's identity #3206

Closed
doctrinebot opened this Issue · 7 comments

2 participants

@doctrinebot

Jira issue originally created by user benjamin:

I'm using a custom mapping type for a LocalDate class (mapped to a DATE field in the MySQL database).

Given the following entity:

/****
 * @Entity
 */
class Timeslot
{
    /****
     * @Id
     * @ManyToOne(targetEntity="Restaurant")
     */
    protected $restaurant;

    /****
     * @Id
     * @Column(type="localdate")
     */
    protected $date;
}

When var_export() -ing the result of UnitOfWork::getEntityIdentifier() on an instance of this class, the result is similar to:

array(
    'restaurant' => '5',
    'date' => LocalDate::*_set*state(array('year' => 2013, 'month' => 6, 'day' => 26))
)

This is a bit weird, because as far as I understand it, it should return the identity as it maps to database fields:

array(
    'restaurant' => '5',
    'date' => '2013-06-26'
)

If we take the $restaurant example, it returns the restaurant ID, and not the Restaurant entity, so my opinion is that it should be the same for $date.

Shouldn't the UnitOfWork use Type::convertToDatabaseValue() on custom mapping types to infer their value, when computing the identity of an entity?

@doctrinebot

Comment created by @ocramius:

[~benjamin] why would getEntityIdentifier convert types? The UoW doesn't worry about the DBAL representation of the objects - actually, the UoW doesn't know of the DBAL at all.

@doctrinebot

Comment created by benjamin:

Your point is valid, but that's still annoying. Why would getEntityIdentifier() return objects?
By the way, UnitOfWork is aware of EntityManager, and thus the Connection, and thus the Platform!
It does use the Connection in commit().

@doctrinebot

Comment created by @ocramius:

[~benjamin] that is because that is the identifier in your object. It's composed by the identifier of an associated entity and a datetime object (scalar)

@doctrinebot

Comment created by benjamin:

[~ocramius] Then why does it return the restaurant ID, and not the Restaurant object?

@doctrinebot

Comment created by @beberlei:

This is not a bug, it is just how it works, the docblock says nothing about how the fields have to look. The UnitOfWork API is mostly serving itself and optimized for that.

@doctrinebot

Issue was closed with resolution "Invalid"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
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.