Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Doctrine] replace ManagerRegistry in doctrine associations doc#18091

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
javiereguiluz merged 1 commit intosymfony:6.2fromMrYamous:doctrine/update
Mar 21, 2023
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletionsdoctrine/associations.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -313,14 +313,14 @@ Now you can see this new code in action! Imagine you're inside a controller::
// ...
use App\Entity\Category;
use App\Entity\Product;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ProductController extends AbstractController
{
#[Route('/product', name: 'product')]
public function index(ManagerRegistry $doctrine): Response
public function index(EntityManagerInterface $entityManager): Response
{
$category = new Category();
$category->setName('Computer Peripherals');
Expand All@@ -333,7 +333,6 @@ Now you can see this new code in action! Imagine you're inside a controller::
// relates this product to the category
$product->setCategory($category);

$entityManager = $doctrine->getManager();
$entityManager->persist($category);
$entityManager->persist($product);
$entityManager->flush();
Expand DownExpand Up@@ -379,9 +378,9 @@ before. First, fetch a ``$product`` object and then access its related

class ProductController extends AbstractController
{
public function show(ManagerRegistry $doctrine, int $id): Response
public function show(ProductRepository $productRepository, int $id): Response
{
$product = $doctrine->getRepository(Product::class)->find($id);
$product = $productRepository->find($id);
// ...

$categoryName = $product->getCategory()->getName();
Expand DownExpand Up@@ -412,9 +411,9 @@ direction::
// ...
class ProductController extends AbstractController
{
public function showProducts(ManagerRegistry $doctrine, int $id): Response
public function showProducts(CategoryRepository $categoryRepository, int $id): Response
{
$category = $doctrine->getRepository(Category::class)->find($id);
$category = $categoryRepository->find($id);

$products = $category->getProducts();

Expand All@@ -433,7 +432,7 @@ by adding JOINs.
a "proxy" object in place of the true object. Look again at the above
example::

$product = $doctrine->getRepository(Product::class)->find($id);
$product = $productRepository->find($id);

$category = $product->getCategory();

Expand DownExpand Up@@ -503,9 +502,9 @@ object and its related ``Category`` in one query::
// ...
class ProductController extends AbstractController
{
public function show(ManagerRegistry $doctrine, int $id): Response
public function show(ProductRepository $productRepository, int $id): Response
{
$product = $doctrine->getRepository(Product::class)->findOneByIdJoinedToCategory($id);
$product = $productRepository->findOneByIdJoinedToCategory($id);

$category = $product->getCategory();

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp