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

How to use it? #5

Open
deadpony opened this issue Feb 12, 2019 · 1 comment
Open

How to use it? #5

deadpony opened this issue Feb 12, 2019 · 1 comment

Comments

@deadpony
Copy link

just how to use it?

@cv65kr
Copy link

cv65kr commented Jan 3, 2020

For more complex example, just look at Sylius Repositories.

https://github.com/Sylius/Sylius/blob/dcc4acd46a3b9d629bb6f7456d7d16dae738988d/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/OrderRepository.php

First step:

    /** @var AssociationHydrator */
    protected $associationHydrator;
    /**
     * {@inheritdoc}
     */
    public function __construct(EntityManager $entityManager, Mapping\ClassMetadata $class)
    {
        parent::__construct($entityManager, $class);
        $this->associationHydrator = new AssociationHydrator($entityManager, $class);
    }

Second step:

    public function findCartForSelectingPayment($id): ?OrderInterface
    {
        /** @var OrderInterface $order */
        $order = $this->createQueryBuilder('o')
            ->andWhere('o.id = :id')
            ->andWhere('o.state = :state')
            ->setParameter('id', $id)
            ->setParameter('state', OrderInterface::STATE_CART)
            ->getQuery()
            ->getOneOrNullResult()
        ;
        $this->associationHydrator->hydrateAssociations($order, [
            'items',
            'items.variant',
            'items.variant.product',
            'items.variant.product.translations',
        ]);
        return $order;
    }

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

2 participants