-
-
Save mikemix/04a71de0f952a2cbc517c7bfb430f1a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$user = new User(); | |
$user->setName('John Doe'); | |
// put user to cache | |
$entityManager->persist($user); | |
$entityManager->flush(); | |
$entityManager->clear(); | |
unset($user); | |
// load user from the cache | |
// avoid database call | |
$user = $entityManager->find(User::class, 1); | |
// create a new post | |
$post = new Post(); | |
$post->setTitle('Awesome title'); | |
$user->addPost($post); | |
$entityManager->persist($post); | |
$entityManager->flush(); | |
$entityManager->clear(); | |
// load user posts from the cache | |
// avoid database call | |
foreach ($user->getPosts() as $post) { | |
echo $post->getTitle(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment