Weitere ähnliche Inhalte Ähnlich wie Orm hero (20) Kürzlich hochgeladen (20) Orm hero10. > Mapping to a relational database involves lots of repetitive,
boiler-plate code.
A framework that allows me to avoid 80% of that is
worthwhile even if it is only 80%.
The problem is in me for pretending it's 100%.
http://martinfowler.com/bliki/OrmHate.html
- Martin Fowler -
13. /**
* @ORMTable(name=“author")
* @ORMEntity
*/
class Author
{
/**
* @ORMColumn(name=“id", type=“string")
* @ORMId
*/
private $id;
/**
* @ORMColumn(name=“name", type="string", length=255)
*/
private $name;
/**
* @ORMOneToMany(targetEntity=“Book", mappedBy=“author",
* cascade={“persist"})
*/
private $books;
}
MAPPING
14. /** @ORMTable(name="book") @ORMEntity */
class Book
{
/**@ORMColumn(name="id", type="string") @ORMId()*/
private $id;
/**@ORMManyToOne(targetEntity="Author", inversedBy="books") */
private $author;
/**@ORMColumn(name="publisher", type="string", length=255) */
private $publisher;
/**@ORMColumn(name="title", type="string", length=255) */
private $title;
/**@ORMColumn(name="published_at", type="datetime",
* nullable=false)
*/
private $publishedAt;
}
MAPPING
17. // query
$author1 = $em->find(Author::class, 1);
// no query
$author2 = $em->find(Author::class, 1);
$author1 === $author2
18. // bypass the identity map
// a query were submitted to the DB
$authorRepository->findByName($authorName);
29. $author = $em->find(Author::class, $authorId);
$author->addBook(. . .);
$this->em->flush();
IMPLICIT
/**
* @Entity
* @ChangeTrackingPolicy(
* “DEFERRED_IMPLICIT"
* )
*/
class Author{}
36. caches DOMAIN
ENTITY MANAGER
UNIT OF WORK REPOSITORY
metadata
cache
sql cache
result
cache
identity
map
2° level
cache
See DoctrineCache @ SymfonyDayIt 2015 - https://vimeo.com/144858752