Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ORMユーザー対談 PHPカンファレンス関西2016

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

ORMユーザー対談 PHPカンファレンス関西2016

PHPカンファレンス関西2016 パネルディスカッション ORMユーザー対談 で使ったスライドです

Avatar for Hisateru Tanaka

Hisateru Tanaka

July 16, 2016
Tweet

More Decks by Hisateru Tanaka

Other Decks in Technology

Transcript

  1. 4&-&$5 '30.CPPLT8)&3&JE $stmt = $pdo->query( "SELECT * FROM books WHERE

    id=1;” ); $book = $stmt->fetch(); echo $book['title'] . "\n";
  2. /** * @ORM\Entity * @ORM\Table(name="books") */ class Book { /**

    * @ORM\Column(type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\Column(type="string", length=100) */ private $title;
  3. use Cake\ORM\Entity; class Book extends Entity { // … }

    use Cake\ORM\Table; class BooksTable extends Table { // … } UBCMF5BCMF3FHJTUSZHFU b#PPLT`  CPPLUBCMFHFU   FDIPCPPLUJUMF
  4. &MPRVFOUͷˎ $book = Book::find(1); echo $book->author->name; class Book extends Model

    { public function author() { return $this->belongsTo(Author::class); } }
  5. &MPRVFOUͷˎ select * from `books` where `books`.`id` = ? limit

    1 select * from `authors` where `authors`.`id` = ? limit 1
  6. $BLF1)1ͷˎ class BooksTable extends Table { public function initialize(array $config)

    { parent::initialize($config); $this->belongsTo('Authors'); } $book = TableRegistry::get('Books')->get(1, [ 'contain' => ['Authors'] ]); echo $book->author->name;
  7. $BLF1)1ͷˎ SELECT Books.id AS `Books__id`, Books.title AS `Books__title`, Books.price AS

    `Books__price`, Books.author_id AS `Books__author_id`, Authors.id AS `Authors__id`, Authors.name AS `Authors__name`, Authors.has_copyright AS `Authors__has_copyright` FROM books Books LEFT JOIN authors Authors ON Authors.id = (Books.author_id) WHERE Books.id = 1 LIMIT 1
  8. %PDUSJOFઃఆʹΑΔ /** * @ORM\ManyToOne(targetEntity="Author", inversedBy="books") * @ORM\JoinColumn(name="author_id", referencedColumnName="id") */ private

    $author; /** * @ORM\ManyToOne(targetEntity="Author", inversedBy="books", fetch="EAGER") * @ORM\JoinColumn(name="author_id", referencedColumnName="id") */ private $author; SELECT t0.id AS id_1, t0.title AS title_2, t0.price AS price_3, t0.author_id AS author_id_4 FROM books t0 WHERE t0.id = 1; SELECT t0.id AS id_1, t0.name AS name_2, t0.has_copyright AS has_copyright_3 FROM authors t0 WHERE t0.id = 1; SELECT t0.id AS id_1, t0.title AS title_2, t0.price AS price_3, t0.author_id AS author_id_4, t5.id AS id_6, t5.name AS name_7, t5.has_copyright AS has_copyright_8 FROM books t0 LEFT JOIN authors t5 ON t0.author_id = t5.id WHERE t0.id = 1;
  9. &MPRVFOU-B[ZWT&BHFS $books = Book::with('author')->get(); foreach ($books as $book) { echo

    $book->author->name; } select * from `books` select * from `authors` where `authors`.`id` in (1, 2, 3, 4) $books = Book::get(); foreach ($books as $book) { echo $book->author->name; } select * from `books` select * from `authors` where `authors`.`id` = 1 select * from `authors` where `authors`.`id` = 1 select * from `authors` where `authors`.`id` = 1 select * from `authors` where `authors`.`id` = 2 … ͜Ε͕ books ͷ਺͚ͩൃੜ
  10. όοϑΝඇόοϑΝ GPSFBDI CPPLTBTCPPL \ ^ GPSFBDI CPPLTBTCPPL \ ^ ($

    ($ GFUDI GSFF GFUDI GSFF Yສ ສϧʔϓ CPPLTΠςϨʔλʔ CPPLT഑ྻ