Doctrine follows a six monthly release schedule and adds a considerable amount of new features in new release. This talk discusses some of the more recent features and how they help you build applications with Symfony2.
The big picture ● 6 month release schedule ● 2.4 on the horizon ● Increased velocity since 2.0 ● Growing team ● Stabilizing and improving minor details
Master-Slave Connection ● Define many slaves and one master ● All reads go to a random slave ● Until one write statement is issued ● Then every read goes to master ● Selectively change back to slave
Arbitrary Joins 1 SELECT 2 u.name, a.title 3 FROM 4 User u 5 JOIN 6 Article a 7 WITH 8 a.user = u.id 1 SELECT 2 u.name, a.title 3 FROM 4 User u 5 JOIN 6 u.article a
Arbitrary Joins 1 SELECT 2 u.name, a.title 3 FROM 4 User u 5 JOIN 6 Article a 7 WITH 8 a.user = u.id 1 SELECT 2 u.name, a.title 3 FROM 4 User u 5 JOIN 6 u.article a
Collection Criteria ● Uses SQL when collection is not yet loaded ● Works on any Selectable – PersistentCollection (associations) – ArrayCollection – EntityReposity
Naming Strategy ● Customize name generation for tables, columns ● Two strategies shipped in core: – DefaultNamingStrategy – UnderscoreNamingStrategy ● Only works for “unnamed” columns! ● Legacy database schema's
Custom ID Generators 1 2 3 use Doctrine\ORM\EntityManager; 4 use Doctrine\ORM\Id\AbstractIdGenerator; 5 6 class SnowflakeIdGenerator extends AbstractIdGenerator 7 { 8 public function generate(EntityManager $em, $entity) 9 { 10 return snowflake_get_id(); // made up API 11 } 12 }
NEW() Operator 1 2 3 class AddressDTO 4 { 5 public function __construct($city, $street) 6 { 7 } 8 } 9 10 $dql = <<11 SELECT new AddressDTO(a.city, a.street) 12 FROM User u JOIN u.address a WHERE u.id = ?1 13 DQL;