4 changed files with 140 additions and 0 deletions
@ -0,0 +1,31 @@ |
|||||
|
<?php |
||||
|
|
||||
|
declare(strict_types=1); |
||||
|
|
||||
|
namespace DoctrineMigrations; |
||||
|
|
||||
|
use Doctrine\DBAL\Schema\Schema; |
||||
|
use Doctrine\Migrations\AbstractMigration; |
||||
|
|
||||
|
/** |
||||
|
* Auto-generated Migration: Please modify to your needs! |
||||
|
*/ |
||||
|
final class Version20210323164758 extends AbstractMigration |
||||
|
{ |
||||
|
public function getDescription() : string |
||||
|
{ |
||||
|
return ''; |
||||
|
} |
||||
|
|
||||
|
public function up(Schema $schema) : void |
||||
|
{ |
||||
|
// this up() migration is auto-generated, please modify it to your needs |
||||
|
$this->addSql('CREATE TABLE product (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); |
||||
|
} |
||||
|
|
||||
|
public function down(Schema $schema) : void |
||||
|
{ |
||||
|
// this down() migration is auto-generated, please modify it to your needs |
||||
|
$this->addSql('DROP TABLE product'); |
||||
|
} |
||||
|
} |
@ -0,0 +1,41 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Entity; |
||||
|
|
||||
|
use App\Repository\ProductRepository; |
||||
|
use Doctrine\ORM\Mapping as ORM; |
||||
|
|
||||
|
/** |
||||
|
* @ORM\Entity(repositoryClass=ProductRepository::class) |
||||
|
*/ |
||||
|
class Product |
||||
|
{ |
||||
|
/** |
||||
|
* @ORM\Id |
||||
|
* @ORM\GeneratedValue |
||||
|
* @ORM\Column(type="integer") |
||||
|
*/ |
||||
|
private $id; |
||||
|
|
||||
|
/** |
||||
|
* @ORM\Column(type="string", length=255) |
||||
|
*/ |
||||
|
private $name; |
||||
|
|
||||
|
public function getId(): ?int |
||||
|
{ |
||||
|
return $this->id; |
||||
|
} |
||||
|
|
||||
|
public function getName(): ?string |
||||
|
{ |
||||
|
return $this->name; |
||||
|
} |
||||
|
|
||||
|
public function setName(string $name): self |
||||
|
{ |
||||
|
$this->name = $name; |
||||
|
|
||||
|
return $this; |
||||
|
} |
||||
|
} |
@ -0,0 +1,50 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Repository; |
||||
|
|
||||
|
use App\Entity\Product; |
||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
||||
|
use Doctrine\Persistence\ManagerRegistry; |
||||
|
|
||||
|
/** |
||||
|
* @method Product|null find($id, $lockMode = null, $lockVersion = null) |
||||
|
* @method Product|null findOneBy(array $criteria, array $orderBy = null) |
||||
|
* @method Product[] findAll() |
||||
|
* @method Product[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
||||
|
*/ |
||||
|
class ProductRepository extends ServiceEntityRepository |
||||
|
{ |
||||
|
public function __construct(ManagerRegistry $registry) |
||||
|
{ |
||||
|
parent::__construct($registry, Product::class); |
||||
|
} |
||||
|
|
||||
|
// /** |
||||
|
// * @return Product[] Returns an array of Product objects |
||||
|
// */ |
||||
|
/* |
||||
|
public function findByExampleField($value) |
||||
|
{ |
||||
|
return $this->createQueryBuilder('p') |
||||
|
->andWhere('p.exampleField = :val') |
||||
|
->setParameter('val', $value) |
||||
|
->orderBy('p.id', 'ASC') |
||||
|
->setMaxResults(10) |
||||
|
->getQuery() |
||||
|
->getResult() |
||||
|
; |
||||
|
} |
||||
|
*/ |
||||
|
|
||||
|
/* |
||||
|
public function findOneBySomeField($value): ?Product |
||||
|
{ |
||||
|
return $this->createQueryBuilder('p') |
||||
|
->andWhere('p.exampleField = :val') |
||||
|
->setParameter('val', $value) |
||||
|
->getQuery() |
||||
|
->getOneOrNullResult() |
||||
|
; |
||||
|
} |
||||
|
*/ |
||||
|
} |
Loading…
Reference in new issue