Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadOnly and changeTrackingPolicy could not be set on embeddable #6711

Closed
sserbin opened this issue Sep 20, 2017 · 2 comments
Closed

ReadOnly and changeTrackingPolicy could not be set on embeddable #6711

sserbin opened this issue Sep 20, 2017 · 2 comments

Comments

@sserbin
Copy link
Contributor

sserbin commented Sep 20, 2017

Pretty much what the subject says.

While I realize this is something that unlikely gets fixed, partially because this is 0.05% case, partially because readOnly is going to be removed in 3.x, I'd like to get some feedback nevertheless.

The use case is the date range embeddable (DateTime start, DateTime end, DateTimeZone tz)
Because the DateTime objects are not constructed properly(with the proper timezone) upon loading from database, they need to be re-constructed (meaning properties of embeddable get re-set) which, in turn, marks the embeddable as dirty in UoW.

Because there's no way to unmark the object as dirty in UoW (or I didn't find it) and readOnly/changeTrackingPolicy=notify are not supported by embeddables - there doesn't seem to be a way to workaround this problem. (a custom doctrine type would not suffice as well because it's only 1-1 mapping and doesn't allow to map a single object into multiple table columns, and vice versa)

Is there some other workaround I've overlooked?

Thanks

@Ocramius
Copy link
Member

Ocramius commented Sep 20, 2017 via email

@beberlei
Copy link
Member

beberlei commented Nov 30, 2019

@sserbin I believe you can hide this behind the Embeddables state by adding unmapped properties:

/** @ORM\Embeddable */
class Date
{
    /** @ORM\Column(type="string") */
    private $date;
    /** @ORM\Column(type="string") */
    private $tz;
    /** not mapped **/
    private $datetime;

    public function getDateTime()
    {
        if ($this->datetime === null) {
             $this->datetime = new DateTime($this->date, new DateTimeZone($this->tz));
        }
        return $this->datetime;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants