Created
April 12, 2017 08:34
-
-
Save integer/3e0c11396d2e8d995ab0f60304a3d7a4 to your computer and use it in GitHub Desktop.
Enum v entitě
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
<?php | |
declare(strict_types=1); | |
// vše je pouze pseudokód, jde jen o ukázku | |
Book extends ORM\Entity | |
{ | |
/** | |
* @PrimaryKey | |
* @Integer | |
*/ | |
private $id; | |
/** | |
* @String | |
*/ | |
private $name; | |
/** | |
* @Enum(BookGenre::class) | |
*/ | |
private $genre; | |
} | |
BookGenre extends Enum | |
{ | |
const FICTION = 1; | |
const NON_FICTION = 2; | |
const HUMOR = 3; | |
const HORROR = 4; | |
const OTHER = 5; | |
} | |
// Při práci s entitou mi pak $book->genre vždy vrací instanci konkrétního Enumu a ne jen "holý" integer, který se ukládá do databáze. | |
// | |
// Dokážu tohle nějak udělat i v pythonu (Flask + SqlAlchemy)? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment