Skip to content

Instantly share code, notes, and snippets.

@ConConovaloff
Last active November 21, 2018 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ConConovaloff/56275468a88064ee4d5f8d31d221cc00 to your computer and use it in GitHub Desktop.
Save ConConovaloff/56275468a88064ee4d5f8d31d221cc00 to your computer and use it in GitHub Desktop.
symfony pallet
=== поиск по нескольким значениям ===
findOneBy([
'some' => 'one',
'another' => 'two',
]);
== raw sql ==
// получаем все алиасы, у которых product brand выставлен в parsing == 1
$idList = $this->getEntityManager()->getConnection()
->executeQuery('
SELECT pba.id
FROM product_brand_alias pba
JOIN product_brand pb on pba.product_brand_id = pb.id
WHERE pb.parsing = 1')
->fetchAll();
$pbaList = $this->getEntityManager()
->getRepository(ProductBrandAlias::class)
->findBy(['id' => array_column($idList, 'id')]);
// raw удаление
$this->getEntityManager()
->getConnection()
->query('DELETE FROM product_brand_alias');
// raw обновление
$this->getEntityManager()
->getConnection()
->exec('UPDATE qr_product
SET brand_id = ' . $newParent->getId() . '
WHERE brand_id = ' . $productBrand->getId());
=== Связи ===
== OneToOne ==
<?php
/** @Entity */
class Customer
{
// ...
/**
* One Customer has One Cart.
* @OneToOne(targetEntity="Cart", mappedBy="customer")
*/
private $cart;
// ...
}
/** @Entity */
class Cart
{
// ...
/**
* One Cart has One Customer.
* @OneToOne(targetEntity="Customer", inversedBy="cart")
* @JoinColumn(name="customer_id", referencedColumnName="id")
*/
private $customer;
// ...
}
== manyToMany ==
== oneToMany ==
== delete entity
$em->remove($guest);
$em->flush();
== render
return $this->render('AppBundle::some.html.php');
// src/AppBundle/Resources/views/some.html.php
return $this->render('AppBundle:Admin:Tools/linkProductBrand.html.php');
// src/AppBundle/Resources/views/Admin/Tools/linkProductBrand.html.php
== запрещаем роуты ==
public function configureRoutes(RouteCollection $collection)
{
$collection->remove('batch');
$collection->remove('create');
$collection->remove('delete');
$collection->remove('export');
$collection->remove('edit');
}
== Типы ==
=== выбор в строку ===
->add('newType', 'choice', [
'choices' => ['alias' => 'alias', 'brand' => 'brand'],
'required' => false,
'label' => 'Тип после переноса',
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment