78 lines
2.1 KiB
PHP
78 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Repository;
|
|
|
|
use App\Entity\Entity1;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
/**
|
|
* @extends ServiceEntityRepository<Entity1>
|
|
*
|
|
* @method Entity1|null find($id, $lockMode = null, $lockVersion = null)
|
|
* @method Entity1|null findOneBy(array $criteria, array $orderBy = null)
|
|
* @method Entity1[] findAll()
|
|
* @method Entity1[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
|
*/
|
|
class Entity1Repository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry)
|
|
{
|
|
parent::__construct($registry, Entity1::class);
|
|
}
|
|
|
|
public function add(Entity1 $entity, bool $flush = false): void
|
|
{
|
|
$this->getEntityManager()->persist($entity);
|
|
|
|
if ($flush) {
|
|
$this->getEntityManager()->flush();
|
|
}
|
|
}
|
|
|
|
public function remove(Entity1 $entity, bool $flush = false): void
|
|
{
|
|
$this->getEntityManager()->remove($entity);
|
|
|
|
if ($flush) {
|
|
$this->getEntityManager()->flush();
|
|
}
|
|
}
|
|
|
|
// /**
|
|
// * @return Entity1[] Returns an array of Entity1 objects
|
|
// */
|
|
// public function findByExampleField($value): array
|
|
// {
|
|
// return $this->createQueryBuilder('e')
|
|
// ->andWhere('e.exampleField = :val')
|
|
// ->setParameter('val', $value)
|
|
// ->orderBy('e.id', 'ASC')
|
|
// ->setMaxResults(10)
|
|
// ->getQuery()
|
|
// ->getResult()
|
|
// ;
|
|
// }
|
|
|
|
public function findOneByName($value): ?Entity1
|
|
{
|
|
return $this->createQueryBuilder('e')
|
|
->andWhere('e.name = :val')
|
|
->setParameter('val', $value)
|
|
->getQuery()
|
|
->getOneOrNullResult()
|
|
;
|
|
}
|
|
|
|
/**
|
|
* https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/schema-manager.html
|
|
*
|
|
* @return \Doctrine\DBAL\Schema\AbstractSchemaManager|null
|
|
* @throws \Doctrine\DBAL\Exception
|
|
*/
|
|
public function getSchemaManager()
|
|
{
|
|
return $this->getEntityManager()->getConnection()->getSchemaManager();
|
|
}
|
|
}
|