Index: tests/Doctrine/Tests/ORM/Functional/Ticket/DDC349Test.php =================================================================== --- tests/Doctrine/Tests/ORM/Functional/Ticket/DDC349Test.php (revision 0) +++ tests/Doctrine/Tests/ORM/Functional/Ticket/DDC349Test.php (revision 0) @@ -0,0 +1,176 @@ +_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); + $this->_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC349Author'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC349Book'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC349Sale'), + )); + + // Create author Joe with two books of which only the first one was sold twice + $author = new DDC349Author(); + $author->name = 'Joe Writer'; + $this->_em->persist($author); + $book = new DDC349Book(); + $book->name = "Joe's bestseller"; + $book->author = $author; + $this->_em->persist($book); + $sale = new DDC349Sale(); + $sale->book = $book; + $sale->dt = new DateTime('2009-01-01'); + $this->_em->persist($sale); + $sale = new DDC349Sale(); + $sale->book = $book; + $sale->dt = new DateTime('2009-01-02'); + $this->_em->persist($sale); + $book = new DDC349Book(); + $book->name = "Joe's flop"; + $book->author = $author; + $this->_em->persist($book); + + // Create author Alice with one book sold once + $author = new DDC349Author(); + $author->name = 'Alice Story'; + $this->_em->persist($author); + $book = new DDC349Book(); + $book->name = "Alice's bestseller"; + $book->author = $author; + $this->_em->persist($book); + $sale = new DDC349Sale(); + $sale->book = $book; + $sale->dt = new DateTime('2010-01-01'); + $this->_em->persist($sale); + + // Create author Dennis with one book never sold + $author = new DDC349Author(); + $author->name = 'Dennis Verspuij'; + $this->_em->persist($author); + $book = new DDC349Book(); + $book->name = "Dennis's flop"; + $book->author = $author; + + $this->_em->flush(); + } + + public function testNestedJoins() + { + $this->_em->clear(); + + // Fetch all authors, their books that have been sold and these sales + $q = $this->_em->createQuery( + 'SELECT A, B, S '. + 'FROM Doctrine\Tests\ORM\Functional\Ticket\DDC349Author A '. + 'LEFT JOIN ( '. + 'A.books B '. + 'INNER JOIN B.sales S '. + ')' + ); + + $result = ''; + foreach($q->getResult() as $author) + { + $result .= $author->name.'['; + foreach($author->books as $book) + { + $result .= $book->name.'['; + foreach($book->sales as $sale) + $result .= $sale->dt->format('Y-m-d,'); + $result .= '],'; + } + $result .= '],'; + } + + $this->assertEquals( + "Joe Writer[Joe's bestseller[2009-01-01,2009-01-02,],],Alice Story[Alice's bestseller[2010-01-01,],],Dennis Verspuij[],", + $result + ); + } +} + +/** + * @Entity + */ +class DDC349Author +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + public $id; + + /** @Column(type="string") */ + public $name; + + /** @OneToMany(targetEntity="DDC349Book", mappedBy="author", cascade={"persist"}) */ + public $books; + + public function __construct() + { + $this->books = new \Doctrine\Common\Collections\ArrayCollection; + } +} + +/** + * @Entity + */ +class DDC349Book +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + public $id; + + /** @Column(type="string") */ + public $name; + + /** + * @ManyToOne(targetEntity="DDC349Author", inversedBy="books") + * @JoinColumn(name="author_id", referencedColumnName="id", nullable=false) + */ + public $author; + + /** @OneToMany(targetEntity="DDC349Sale", mappedBy="book", cascade={"persist"}) */ + public $sales; + + + public function __construct() + { + $this->sales = new \Doctrine\Common\Collections\ArrayCollection; + } +} + +/** + * @Entity + */ +class DDC349Sale +{ + /** + * @Id + * @Column(type="integer") + * @GeneratedValue + */ + public $id; + + /** @Column(type="datetime") */ + public $dt; + + /** + * @ManyToOne(targetEntity="DDC349Book", inversedBy="sales") + * @JoinColumn(name="book_id", referencedColumnName="id", nullable=false) + */ + public $book; +} Property changes on: tests\Doctrine\Tests\ORM\Functional\Ticket\DDC349Test.php ___________________________________________________________________ Added: svn:mime-type + text/x-php Added: svn:keywords + Id Rev Date Author HeadURL Added: svn:eol-style + native