Skip to content

Instantly share code, notes, and snippets.

@integer
Created April 12, 2017 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save integer/3e0c11396d2e8d995ab0f60304a3d7a4 to your computer and use it in GitHub Desktop.
Save integer/3e0c11396d2e8d995ab0f60304a3d7a4 to your computer and use it in GitHub Desktop.
Enum v entitě
<?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