-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added favorite table and migration
- Loading branch information
Showing
7 changed files
with
151 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?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 Version20231118065043 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 favorite (id INT AUTO_INCREMENT NOT NULL, fruit_id INT NOT NULL, date_added DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_68C58ED9BAC115F0 (fruit_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); | ||
$this->addSql('ALTER TABLE favorite ADD CONSTRAINT FK_68C58ED9BAC115F0 FOREIGN KEY (fruit_id) REFERENCES fruits (id)'); | ||
$this->addSql('ALTER TABLE fruits CHANGE created_at created_at DATETIME DEFAULT NULL, CHANGE updated_at updated_at DATETIME DEFAULT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE favorite DROP FOREIGN KEY FK_68C58ED9BAC115F0'); | ||
$this->addSql('DROP TABLE favorite'); | ||
$this->addSql('ALTER TABLE fruits CHANGE created_at created_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', CHANGE updated_at updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use App\Repository\FavoriteRepository; | ||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity(repositoryClass: FavoriteRepository::class)] | ||
class Favorite | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column] | ||
private ?int $id = null; | ||
|
||
#[ORM\OneToOne(inversedBy: 'favorite', cascade: ['persist', 'remove'])] | ||
#[ORM\JoinColumn(nullable: false)] | ||
private ?Fruit $fruit = null; | ||
|
||
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)] | ||
private ?\DateTimeInterface $dateAdded = null; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getFruit(): ?Fruit | ||
{ | ||
return $this->fruit; | ||
} | ||
|
||
public function setFruit(Fruit $fruit): static | ||
{ | ||
$this->fruit = $fruit; | ||
|
||
return $this; | ||
} | ||
|
||
public function getDateAdded(): ?\DateTimeInterface | ||
{ | ||
return $this->dateAdded; | ||
} | ||
|
||
public function setDateAdded(?\DateTimeInterface $dateAdded): static | ||
{ | ||
$this->dateAdded = $dateAdded; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Repository; | ||
|
||
use App\Entity\Favorite; | ||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
|
||
/** | ||
* @extends ServiceEntityRepository<Favorite> | ||
* | ||
* @method Favorite|null find($id, $lockMode = null, $lockVersion = null) | ||
* @method Favorite|null findOneBy(array $criteria, array $orderBy = null) | ||
* @method Favorite[] findAll() | ||
* @method Favorite[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | ||
*/ | ||
class FavoriteRepository extends ServiceEntityRepository | ||
{ | ||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
parent::__construct($registry, Favorite::class); | ||
} | ||
|
||
// /** | ||
// * @return Favorite[] Returns an array of Favorite objects | ||
// */ | ||
// public function findByExampleField($value): array | ||
// { | ||
// return $this->createQueryBuilder('f') | ||
// ->andWhere('f.exampleField = :val') | ||
// ->setParameter('val', $value) | ||
// ->orderBy('f.id', 'ASC') | ||
// ->setMaxResults(10) | ||
// ->getQuery() | ||
// ->getResult() | ||
// ; | ||
// } | ||
|
||
// public function findOneBySomeField($value): ?Favorite | ||
// { | ||
// return $this->createQueryBuilder('f') | ||
// ->andWhere('f.exampleField = :val') | ||
// ->setParameter('val', $value) | ||
// ->getQuery() | ||
// ->getOneOrNullResult() | ||
// ; | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters