Skip to content

Commit

Permalink
Ref #215: create Bank entity
Browse files Browse the repository at this point in the history
  • Loading branch information
LucileDT committed Jul 7, 2020
1 parent 6edde69 commit 2897b25
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Entity/Bank.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity(repositoryClass="App\Repository\BankRepository")
*/
class Bank
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;

/**
* @ORM\Column(name="name", type="string", length=255, unique=true)
*/
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;
}
}
30 changes: 30 additions & 0 deletions src/Migrations/Version20200707170739.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20200707170739 extends AbstractMigration
{
public function getDescription() : string
{
return 'Create bank table to store banks name.';
}

public function up(Schema $schema) : void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('CREATE TABLE bank (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_D860BF7A5E237E06 (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
}

public function down(Schema $schema) : void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('DROP TABLE bank');
}
}
50 changes: 50 additions & 0 deletions src/Repository/BankRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Repository;

use App\Entity\Bank;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;

/**
* @method Bank|null find($id, $lockMode = null, $lockVersion = null)
* @method Bank|null findOneBy(array $criteria, array $orderBy = null)
* @method Bank[] findAll()
* @method Bank[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class BankRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Bank::class);
}

// /**
// * @return Bank[] Returns an array of Bank objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('b')
->andWhere('b.exampleField = :val')
->setParameter('val', $value)
->orderBy('b.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/

/*
public function findOneBySomeField($value): ?Bank
{
return $this->createQueryBuilder('b')
->andWhere('b.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}

0 comments on commit 2897b25

Please sign in to comment.