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

DDC-2484: Lazy loaded associated entities do not trigger the postLoad event #3203

Closed
doctrinebot opened this issue Jun 3, 2013 · 3 comments
Assignees
Labels

Comments

@doctrinebot
Copy link

Jira issue originally created by user tom_anderson:

An entity retrieved with $entity = $em->find will correctly trigger the postLoad event but an entity associated with that entity $association = $entity->association which is lazy loaded will retrieve and return the associated entity without triggering postLoad. Eager loading does follow the lifecycle path of triggering postLoad.

Functional Test:
#685

@doctrinebot
Copy link
Author

Comment created by @FabioBatSilva:

Hi Tom,

You CANNOT check the entity class by using get*class, doctrine uses the pattern proxy to delay the load from database.

Then $args->getEntity() might be a different class that extends your entity
In this case you should always check using instanceof :

$entity = $args->getEntity();

if ($entity instanceof DDC2484_Car) {
    $entity->setBrand('BMW');
}

Also when you try to load the same entity more than once :

$eagerDriver->getCar();
$lazyDriver->getCar();

The entity will be cached at the first time, triggering onLoad just once.

It means that the entity will be always the same instance,
it's not loaded from database untill you clean up the entity manager.

assertSame($eagerDriver->getCar(), $lazyDriver->getCar());

@doctrinebot
Copy link
Author

Comment created by @beberlei:

Wrong assumption using get_class

@doctrinebot
Copy link
Author

Issue was closed with resolution "Invalid"

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

No branches or pull requests

2 participants